package work;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class A1129singal {
static int N,ans;
static char[][] data;
static boolean[][] map;
static int mincol;
static int area[];
static boolean used;
public static void main(String[] args) throws FileNotFoundException {
/* Scanner sc=new Scanner(System.in); */
Scanner sc = new Scanner(new File("src/11290"));
while (true) {
N = sc.nextInt();
data = new char[N][N + 1];
map = new boolean[N][N];
area = new int[N];
mincol = 0xfffffff;
used=false;
ans=1;
int num = 0;
if (N == 0) {
break;
}
sc.nextLine();
for (int i = 0; i < N; i++) {
char[] line = sc.nextLine().toCharArray();
for (int j = 2; j < line.length; j++) {
data[i][j] = line[j];
if (data[i][j] == 'A') {
num = 0;
}
if (data[i][j] == 'B') {
num = 1;
}
if (data[i][j] == 'C') {
num = 2;
}
if (data[i][j] == 'D') {
num = 3;
}
map[i][num] = true;
//
}
}
dfs(0, 1);
if (ans == 1) {
System.out.println(ans + " channel needed.");
} else {
System.out.println(ans + " channels needed.");
}
}
}
// 第几区域,总数
private static void dfs(int a, int tol) {
if(used){return;}
if ( a>= N) { used = true; return; }
/*if (a == N) {
if (mincol > tol) {
mincol = tol;
}
return;
}*/
for (int i = 1; i <= tol; i++) {
if (isok(a, i)) {
area[a] = i;
dfs(a + 1, tol);
area[a] = 0;
}
}
if(!used){
ans++;
dfs(a, tol + 1);}
}
private static boolean isok(int a, int colnum) {
for (int j = 0; j < N; j++) {
if (map[a][j] && area[j] == colnum) {
return false;
}
}
return true;
}
}
//
2
0 0
0 0
4
0 1 1 0
1 0 1 1
1 1 0 1
0 1 1 0
4
0 1 1 1
1 0 1 1
1 1 0 1
1 1 1 0
0
//
1 channel needed.
3 channels needed.
4 channels needed.