import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; /** * Created by cteam040 on 10/22/16. */ public class Tribune { private static char[][] matrix = null; private static Set okLine = null; private static char getWrongChar() { HashMap, Integer> counts = new HashMap<>(); for (int i = 0; i < matrix.length; i++) { Set line = new HashSet<>(); for (int j = 0; j < matrix.length; j++) { line.add(matrix[i][j]); } if (counts.containsKey(line)) { counts.put(line, (counts.get(line) + 1)); } else counts.put(line, 1); } Set badLine = null; for (Set line : counts.keySet()) { int count = counts.get(line); if (count == 1) { badLine = line; } else { okLine = line; } } for (char c : okLine) { badLine.remove(c); } char result = 0; for (char c: badLine) { result = c; } return result; } private static void loadMatrixLine(int x, String line) { for (int i = 0; i < line.length(); i++) { matrix[x][i] = line.charAt(i); } } private static void printResult(int x, int y, char c) { System.out.println((x + 1) + " " + (y + 1) + " " + c); } private static void runTestCase(BufferedReader in, int n) throws IOException { matrix = new char[n][n]; for (int i = 0; i < n; i++) { loadMatrixLine(i, in.readLine()); } char badChar = getWrongChar(); int badX = -1; int badY = -1; outer: for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (matrix[i][j] == badChar) { badX = i; badY = j; break outer; } } } if (badX != -1) { for (int i = 0; i < n; i++) { okLine.remove(matrix[badX][i]); } char result = 0; for (char c: okLine) { result = c; } printResult(badX, badY, result); return; } for (int i = 0; i < n; i++) { Map lineMap = new HashMap<>(); for (int j = 0; j < n; j++) { char current = matrix[i][j]; if (!lineMap.containsKey(current)) { lineMap.put(current, j); continue; } int oldPos = lineMap.get(current); int newPos = j; int count = 0; for (int k = 0; k < n; k++) { if (matrix[k][oldPos] == current) { count++; } } int badPos = count > 1 ? oldPos : newPos; for (int k = 0; k < n; k++) { okLine.remove(matrix[k][badPos]); } char result = 0; for (char c: okLine) { result = c; } printResult(i, badPos, result); } } } public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); while (true) { String line = in.readLine(); if (line == null) break; int nTest = Integer.parseInt(line); runTestCase(in, nTest); } } }