import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.util.stream.Collectors;

/**
 * Created by tym12 on 10/22/16.
 */
public class Tribune {


    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        try {
            String line;
            while ((line = reader.readLine()) != null){
                int n = Integer.parseInt(line);

                ArrayList<String> all = new ArrayList<>(n);
                ArrayList<String> sorted = new ArrayList<>(n);
                for (int i = 0; i < n; i++) {
                    String next = reader.readLine();
                    all.add(next);

                    char[] chars = next.toCharArray();
                    Arrays.sort(chars);

                    sorted.add(new String(chars));
                }


                String first = sorted.get(0);
                String second = sorted.get(1);
                if (first.equals(second)) {
                    // hledame chybny
                    for (int i = 2; i < n; i++) {
                        String next = sorted.get(i);

                        if (!next.equals(first)) {
                            printdiff(first, next, i, all);
                        }
                    }

                } else {
                    // jeden z nich je chybny

                    String third = sorted.get(2);
                    if (first.equals(third)) {
                        // chybny je 2
                        printdiff(first, second, 1, all);

                    } else {
                        // chybny je 1
                        printdiff(second, first, 0, all);

                    }
                }
            }
        } catch (IOException e) {

        }


    }


    private static char findDup(String s1) {
        char last = 0;
        for (int i = 0; i < s1.length(); i++) {
            if (last == s1.charAt(i)) {
                return s1.charAt(i);
            }
            last = s1.charAt(i);
        }
        return 0;
    }


    private static void printdiff(String good, String bad, int badid, ArrayList<String> all) throws IOException {
        Set<Character> uniques = uniques(bad, good);
        char diff;
        Iterator<Character> iterator = uniques.iterator();
        if (!iterator.hasNext())
            diff = findDup(bad);
        else
            diff = iterator.next();

        Set<Character> uniques2 = uniques(good, bad);
        Iterator<Character> iterator1 = uniques2.iterator();
        if (!iterator1.hasNext())
            throw new IOException();
        char d = iterator1.next();

        System.out.println((badid +1) + " " + (all.get(badid).indexOf(diff) + 1) + " " + d);
    }

    private static Set<Character> uniques(String first, String second) {
        Set<Character> a = first.chars().mapToObj(c -> (char) c).collect(Collectors.toSet());
        Set<Character> b = second.chars().mapToObj(c -> (char) c).collect(Collectors.toSet());
        a.removeAll(b);
        return a;
    }

/*

    public static void main(String[] args)  {

        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String nrS;
        try {
            do {
                ArrayList<String> gr = new ArrayList<>();
                ArrayList<char[]> chars = new ArrayList<>();
                nrS= bufferedReader.readLine();
                int n = Integer.parseInt(nrS);

                for (int i= 0; i < n; i++)
                {
                    String l = bufferedReader.readLine();
                    gr.add(l);
                    char[] line = l.toCharArray();
                    Arrays.sort(line);
                    chars.add(line);
                }

                char[] correct = findCorrect(chars);
                char bad = 0;
                char good = 0;
                for (int i = 0; i < n; i++) {
                   if (!Arrays.equals(chars.get(i), correct))
                   {
                       Set<Character> s = uniques(gr.get(i),new String(correct));
                       for (char c :s)
                       {
                           bad = c;
                           break;

                       }
                       Set<Character> g = uniques(new String(correct),gr.get(i));
                       for (char c :g)
                       {
                           good = c;
                           break;

                       }
                       if (s.isEmpty() && !g.isEmpty())
                       {
                           int ix = Arrays.toString(chars.get(i)).indexOf(bad);
                           if (ix != -1) {

                               System.out.println((i + 1) + " " + (gr.get(i).indexOf(chars.get(i)[ix]) + 1) + " " + bad);
                           }
                       }

                        System.out.println((i+1)+" "+(gr.get(i).indexOf(bad)+1)+" "+good);
                       break;
                   }
                }
            }
            while(nrS != null);
        } catch (IOException e) {
            //
        }

    }

    private static char[] findCorrect(ArrayList<char[]> chars) {
        char[] line = chars.get(0);
        //for (int i = 1; i < chars.size(); i++)
        {
            if (line.equals(chars.get(1)))
                return line;
            //if (i == 2)
                return chars.get(2);
        }
        //return line;
    }

    private static Set<Character> uniques(String first, String second) {
        Set<Character> a = first.chars().mapToObj(c -> (char) c).collect(Collectors.toSet());
        Set<Character> b = second.chars().mapToObj(c -> (char) c).collect(Collectors.toSet());
        a.removeAll(b);
        return a;
    }
   // */

}
