#include <iostream>
using namespace std;
int main(){
freopen("input.txt","r",stdin);
int T,x;
cin>>T;
for (x = 0; x < T; x++){
char A[9][9];
int i,j;
for (i = 0; i < 9; i++){
for (j = 0; j < 9; j++){
cin>>A[i][j];
}
}
int cnt[10]={0},check = 1,k;
for (i = 0; i < 9; i++){
for (j = 0; j < 9; j++){
if (A[i][j]>= '1' && A[i][j]<='9'){
cnt[A[i][j]-'0']++;
if (cnt[A[i][j]-'0'] > 1){
check = 0;
break;
}
}
}
if (check == 0) break;
for (k = 1; k <= 9; k++){
cnt[k]= 0;
}
for (j = 0; j < 9; j++){
if (A[j][i]>= '1' && A[j][i]<='9'){
cnt[A[j][i]-'0']++;
if (cnt[A[j][i]-'0'] > 1){
check = 0;
break;
}
}
}
if (check == 0) break;
for (k = 1; k <= 9; k++){
cnt[k]= 0;
}
}
for (i = 0; i < 9; i+=3){
for (j = 0; j < 9; j+=3){
for (int i1 = i; i1 < i+3; i1++)
for (int j1 = j; j1 < j+3; j1++){
if (A[i1][j1] > '0' && A[i1][j1] <= '9'){
cnt[A[i1][j1]-'0']++;
if (cnt[A[i1][j1]-'0'] > 1){
check = 0;
break;
}
}
}
if (check == 0) break;
for (k = 1; k <= 9; k++){
cnt[k]= 0;
}
}
if (check == 0) break;
}
cout<<"#"<<x+1<<" "<<check<<endl;
}
return 0;
}
/*
20
...14..2.
..6......
.........
..1......
.67.....9
......81.
.3......6
.....7...
...5...7.
....2..9.
....6....
71..75...
.7.......
....83...
..8..7.6.
.....2...
.1.2.....
.2..3....
..4...63.
.........
5......9.
...56....
4.3.....1
...7.....
...5.....
.........
.........
........2
......6..
..14..8..
.........
.........
....3....
5.86.....
.9....4..
....5....
.9..4....
1.....6..
..3......
.........
...7.....
3...5....
..7..4...
.........
....7....
7...4....
...865...
.1.2.....
.....9...
....5.5..
.........
......2..
.........
.........
.4.......
..4......
...1..7..
.........
...3...6.
.....6.9.
....1....
......2..
...8.....
..5......
...8...3.
.5..2....
.........
........9
......4..
........7
.1.......
24....9..
.........
.........
.9......1
8........
.99357...
.......4.
...8.....
.1....4.9
...5.4...
...2..6..
...1.....
.........
...5.1..8
.3.......
...9....3
4........
......38.
........4
....8....
......5..
....4..2.
...3.9...
..18..9..
.....51..
..3..8...
.12.3....
.....7..1
......5..
.........
.........
93..2.4..
..7...3..
.........
...34....
.....3...
.....52..
....4.9..
..21..3..
.........
........3
...2.....
.....7...
...61....
..9......
.......9.
.87654321
2........
3........
4........
5........
6........
7........
8........
9........
.........
4........
......6..
...38....
.5...6..1
8......6.
.........
..7.9....
...6.....
........1
.....6...
4.....38.
7........
....53...
....68...
3..9.....
.....211.
.........
.8.......
....2....
.6....1.4
...9..7..
.......4.
..1..8...
.........
.....5.7.
..3..56..
.........
..2......
.....271.
.........
.2.......
.5.......
....9...8
.....16..
....6....
...9.....
.........
..3.....1
.........
1.....3..
....2.6..
.9.....7.
.........
8..8.....
......83.
2........
7....7.95
...1....2
.8.9.....
..519....
5........
.........
.........
*/