def check(mlist):
ans=1
for i in range(9):
if len(set(mlist[i]))==9:
ans=1
else:
return 0
for i in range(9):
klist=[]
for j in range(9):
klist.append(mlist[j][i])
if len(set(klist))==9:
ans=1
else:
return 0
for i in range(0, 7, 3):
for x in range(0, 7, 3):
klist=[]
for j in range(3):
for k in range(3):
klist.append(mlist[j+i][k+x])
if len(set(klist))==9:
ans=1
else:
return 0
return 1
t=int(input())
for tc in range(1, t+1):
mlist=[]
for i in range(9):
mlist.append(list(map(int, input().split())))
print(f"#{tc} {check(mlist)}")
import java.util.HashSet;
import java.util.Scanner;
public class d2_1974 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tc = 1; tc <= t; tc++) {
int[][] arr = new int[9][9];
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
arr[i][j] = sc.nextInt();
}
}
System.out.println("#"+t+" "+check(arr));
}
}
private static int check(int[][] mlist) {
int ans=1;
HashSet<Integer> hs= new HashSet<Integer>();
for(int i=0;i<9;i++) {
for(int j=0;j<9;j++) {
hs.add(mlist[i][j]);
}
if (hs.size()==9) {
ans=1;
}
else {
return 0;
}
hs.clear();
}
for(int i=0;i<9;i++) {
for(int j=0;j<9;j++) {
hs.add(mlist[j][i]);
}
if (hs.size()==9) {
ans=1;
}
else {
return 0;
}
hs.clear();
}
for(int i=0;i<7;i+=3) {
for(int j=0;j<7;j+=3) {
for(int x=0;x<3;x++) {
for(int y=0;y<3;y++) {
hs.add(mlist[x+i][y+j]);
}
}
if(hs.size()==9) {
ans=1;
}
else {
return 0;
}
hs.clear();
}
}
return 1;
}
}
import java.util.Scanner;
public class d2_1974 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int tc = 1; tc <= t; tc++) {
int[][] arr = new int[9][9];
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
arr[i][j] = sc.nextInt();
}
}
System.out.println("#" + tc + " " + check(arr));
}
}
private static int check(int[][] mlist) {
int ans = 1;
int res = 0;
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
res += mlist[i][j];
}
if (res == 45) {
ans = 1;
res = 0;
} else {
return 0;
}
}
for (int i = 0; i < 9; i++) {
for (int j = 0; j < 9; j++) {
res += mlist[j][i];
}
if (res == 45) {
ans = 1;
res = 0;
} else {
return 0;
}
}
for (int i = 0; i < 7; i += 3) {
for (int j = 0; j < 7; j += 3) {
for (int x = 0; x < 3; x++) {
for (int y = 0; y < 3; y++) {
res += mlist[x + i][y + j];
}
}
if (res == 45) {
ans = 1;
res = 0;
} else {
return 0;
}
}
}
return 1;
}
}
1, 2)
3)