import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuffer sb = new StringBuffer();
int cases = Integer.parseInt(br.readLine().trim());
for (int i = 0; i < cases; i++) {
if (i > 0) {
br.readLine();
}
int counterX = 0, counterO = 0;
String str = "";
boolean[][] arrX = new boolean[3][3];
boolean[][] arrO = new boolean[3][3];
for (int j = 0; j < 3; j++) {
str = br.readLine();
for (int z = 0; z < 3; z++) {
if (str.charAt(z) == 'X') {
counterX++;
arrX[j][z] = true;
}
if (str.charAt(z) == 'O') {
counterO++;
arrO[j][z] = true;
}
}
}
if (win(arrX) && win(arrO)) {
sb.append("no\n");
}else if (win(arrO) &&counterX!=counterO) {
sb.append("no\n");
}else if (win(arrX) &&counterX!=counterO+1) {
sb.append("no\n");
}else {
if (counterO == counterX) {
sb.append("yes\n");
} else if (counterO + 1 == counterX) {
sb.append("yes\n");
} else {
sb.append("no\n");
}
}
}
System.out.print(sb);
}
static boolean win(boolean[][] arr) {
for (int i = 0; i < 3; i++) {
boolean flag = true;
for (int j = 0; j < 3; j++) {
flag &= arr[i][j];
}
if (flag) {
return true;
}
}
for (int i = 0; i < 3; i++) {
boolean flag = true;
for (int j = 0; j < 3; j++) {
flag &= arr[j][i];
}
if (flag) {
return true;
}
}
if (arr[0][0] && arr[1][1] && arr[2][2]) {
return true;
}
if (arr[2][0] && arr[1][1] && arr[0][2]) {
return true;
}
return false;
}
}
No comments:
Post a Comment