import java.io.BufferedReader;
import java.io.InputStreamReader;

public class ColorfulTribune2 {
	static public char[][] pole;
	static public boolean[][] positionIsTakenByShirt;
	static public int failedPerson = -1;
	static public int commonMask;
	
	public static void main(String [] arguments) throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line;
		while ((line = reader.readLine()) != null) {
			int n = Integer.parseInt(line);
			pole = new char[n][];
			positionIsTakenByShirt = new boolean[n][30];
			for (int i=0; i<n; i++) {
				pole[i] = reader.readLine().toCharArray();
			}
			commonMask = commonMask();
			for (int i=0; i<n; i++) {
				if (mask(pole[i]) != commonMask) {
					failedPerson = i;
				}
			}
			
			for (int person=0; person<n; person++) {
				if (person == failedPerson) continue;
				for (int position=0; position<n; position++) {
					positionIsTakenByShirt[position][pole[person][position]-'A'] = true;
				}
			}
			
			int whereShouldBe = 0;
			char whatShouldBe = 0;
			here: for (int position=0; position<n; position++) {
				for (char c = 'A'; c <= 'Z'; c++) {
					int mask = (1 << (c-'A'));
					if ((commonMask & mask) == 0) continue;
					if (positionIsTakenByShirt[position][c-'A']) continue;
					char[] copy = copy(pole[failedPerson]);
					copy[position] = c;
					if (mask(copy) == commonMask) {
						whereShouldBe = position;
						whatShouldBe = c;
						break here;
					}
				}
			}
			
			System.out.println((failedPerson+1)+" "+(whereShouldBe+1)+" "+whatShouldBe);
		}
	}
	
	public static char[] copy(char[] c) {
		char[] r = new char[c.length];
		for (int i=0;i<r.length; i++) {
			r[i] = c[i];
		}
		return r;
	}
	
	public static int mask(char[] line) {
		int mask = 0;
		for (char c : line) {
			mask |= (1 << (c-'A'));
		}
		return mask;
	}
	
	public static int commonMask() {
		if (pole.length == 3) {
			int a = mask(pole[0]);
			int b = mask(pole[1]);
			int c = mask(pole[2]);
			if (a == b) return a;
			if (b == c) return c;
			if (a == c) return a;
		}
		
		int previous = 0;
		for (char [] line : pole) {
			int current = mask(line);
			if (current == previous) {
				return previous;
			}
			previous = current;
		}
		throw new RuntimeException("WTF");
	}
}
