public class Bankomat {

static int m = 10000;

static int []sekwencja = new int[m];

static int t = 1000;

static int [][][] sekTab = new int[t][][];

public static void main(String[] args){

String str = "";

int n = 0;

int dl = 0;

String [] spl = null;

StringTokenizer strTok;

BufferedReader br = new BufferedReader(

new InputStreamReader(

System.in)

);

System.out.println("wpisz");

try{

strTok = new StringTokenizer(br.readLine());

n = Integer.parseInt(strTok.nextToken());

for(int i = 0; i < n; i++){

strTok = new StringTokenizer(br.readLine());

dl = Integer.parseInt(strTok.nextToken());

str = strTok.nextToken();

spl = str.split("");

for(int j = 0; j < dl; j++){

sekwencja[j] = Integer.parseInt(spl[j+1]);

}

sekTab[i] = zrobB(dl);

}

}catch(IOException e){

System.err.println("Input Stream ERROR");

}

int wynik = 0;

int licz = 0;

int []pin = new int[4];

for(int p1 = 0; p1 < 10; p1++){

pin[0] = p1;

for(int p2 = 0; p2 < 10; p2++){

pin[1] = p2;

for(int p3 = 0; p3 < 10; p3++){

pin[2] = p3;

for(int p4 = 0; p4 < 10; p4++){

pin[3] = p4;

for(int k = 0; k < n; k++){

if(wB(pin, sekTab[k]) != 0){

licz++;

}

if(licz == n){

wynik++;

}

}

licz = 0;

}

}

}

}

System.out.println(wynik);

}

static int [][] zrobB(int dlugosc){

int [][]a = new int[dlugosc][10];

{

int i = dlugosc-1;

for(int j = 0; j < 10; j++) {

a[i][j] = -1;

}

a[i][sekwencja[i]] = i;

}

for(int i = dlugosc-2; i >= 0; i--){

for(int j = 0; j < 10; j++){

a[i][j] = a[i+1][j];

}

a[i][sekwencja[i]] = i;

}

return a;

}

static int wB(int []pin, int[][]a){

int pos = 0;

for(int k = 0; k <4 && pos != -1; k++){

pos = a[pos][pin[k]];

}

if(pos != -1) {

return 1;

}

else {

return 0;

}

}

}