import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

/**
 * Created by cteam004 on 10/22/16.
 */
public class Tribune {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();

        while (line != null) {
            int count = Integer.parseInt(line);

            String[][] map = new String[3][count];
            HashMap<String, Integer> hm = new HashMap<>();

            for (int i = 0; i < 3; i++) {
                line = br.readLine();
                map[i] = line.split("");

                for (String string : map[i]) {
                    if (hm.containsKey(string)) {
                        hm.put(string, hm.get(string) + 1);
                    } else {
                        hm.put(string, 1);
                    }
                }
            }

            String wrongC = "";
            for (String s : hm.keySet()) {
                if (hm.get(s) < 2){
                    wrongC = s;
                    break;
                }
            }

            boolean kill = false;
            if (wrongC.equals("")){
                for (int j = 3; j < count; j++) {
                    String[] p = br.readLine().split("");

                    if (!kill) {
                        for (int i = 0; i < count; i++) {
                            if (!hm.containsKey(p[i])) {
                                for (int k = 0; k < count; k++) {
                                    if (k != i) {
                                        hm.remove(p[k]);
                                    }
                                }
                                System.out.println((j + 1) + " " + (i + 1) + " " + hm.keySet().toArray()[0]);
                                kill = true;
                                break;
                            }
                        }
                    }
                }
            } else {
                hm.remove(wrongC);
                for (int j = 0; j < 3; j++) {
                    String[] p = map[j];

                    if (!kill) {
                        for (int i = 0; i < count; i++) {
                            if (!hm.containsKey(p[i])) {
                                for (int k = 0; k < count; k++) {
                                    if (k != i) {
                                        hm.remove(p[k]);
                                    }
                                }
                                System.out.println((j + 1) + " " + (i + 1) + " " + hm.keySet().toArray()[0]);
                                kill = true;
                                break;
                            }
                        }
                    }
                }
            }

            line = br.readLine();
        }
    }
}