import java.util.*;
import java.io.*;
import java.text.*;

public class NickyEnMark{
    public static void main(String[] args) throws IOException {
        HashMap<Set<Character>,HashSet<String>> primes = new HashMap<>();
        int x = 0;
        for (int p = 10000; p < 100000; p++) {
            boolean isPrime = true;
            for (int d = 2; d <= Math.sqrt(p); d++) {
                if (p % d == 0) {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime) {
                x++;
                String pp = "" + p;
                Set<Character> s = new HashSet<>();
                for (int i = 0; i < 5; i++) {
                    s.add(pp.charAt(i));
                }

                HashSet<String> ppp;
                if (primes.containsKey(s)) {
                    ppp = primes.get(s);
                } else {
                    ppp = new HashSet<>();
                    primes.put(s, ppp);
                }

                ppp.add(pp);
            }
        }

        // System.out.println(primes.size());
        // System.out.println(x);

        Set<Character> s = new HashSet<>();

        int m = 0;
        for (Set<Character> key : primes.keySet()) {
            if (primes.get(key).size() >= m) {
                m = primes.get(key).size();
                s = key;
            }
        }

        // System.out.println(m);
        // System.out.println(s);
        // System.out.println(primes.get(s));

        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        for (int i = 0; i < n; i++) {
            ArrayList<Set<Character>> candidates = new ArrayList<>();
            candidates.add(new HashSet<Character>(Arrays.asList('1', '2', '3', '4', '5', '6', '7', '8', '9')));
            for (int j = 0; j < 3; j++) {
                candidates.add(new HashSet<Character>(Arrays.asList('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')));
            }
            candidates.add(new HashSet<Character>(Arrays.asList('1', '3', '7', '9')));

            String p1 = "12347";
            String p2 = "56809";

            System.out.println(p1);
            System.out.flush();
            String a1 = scanner.next();
            if (a1.equals("ggggg")) {
                continue;
            }
            System.out.println(p2);
            System.out.flush();
            String a2 = scanner.next();
            if (a2.equals("ggggg")) {
                continue;
            }

            Set<Character> idx = new HashSet<>();

            updateCandidates(candidates, a1, p1);
            updateCandidates(candidates, a2, p2);

            for (int j = 0; j < a1.length(); j++) {
                char c = a1.charAt(j);
                if (c != 'w') {
                    idx.add(p1.charAt(j));
                }
            }
            for (int j = 0; j < a2.length(); j++) {
                char c = a2.charAt(j);
                if (c != 'w') {
                    idx.add(p2.charAt(j));
                }
            }

            Set<String> possible = (Set<String>)primes.get(idx).clone();

            updateSet(possible, candidates);
            // System.out.println("idx = " + idx);
            // System.out.println(candidates);
            // System.out.println(possible);

            boolean stop = false;
            while (true) {
                // Pick any from possible
                String toCheck = possible.iterator().next();
                System.out.println(toCheck);
                System.out.flush();
                String a = scanner.next();
                if (a.equals("ggggg")) {
                    stop = true;
                    break;
                }

                updateCandidates(candidates, a, toCheck);
                updateSet(possible, candidates);
                // System.out.println(candidates);
                // System.out.println(possible);
            }
        }
    }

    static void updateCandidates(ArrayList<Set<Character>> candidates, String a, String p) {
        Set<Character> encountered = new HashSet<>();
        for (int j = 0; j < a.length(); j++) {
            char c = a.charAt(j);
            if (c == 'g') {
                candidates.set(j, new HashSet<Character>(Arrays.asList(p.charAt(j))));
            } else if (c == 'w') {
                if (encountered.contains(p.charAt(j))) {
                    candidates.get(j).remove(p.charAt(j));
                } else {
                    for (int k = 0; k < 5; k++) {
                        if (candidates.get(k).size() > 1) {
                            candidates.get(k).remove(p.charAt(j));
                        }
                    }
                }
            } else {
                candidates.get(j).remove(p.charAt(j));
            }
            encountered.add(p.charAt(j));
        }
    }

    static void updateSet(Set<String> primes, ArrayList<Set<Character>> candidates) {
        ArrayList<String> toRemove = new ArrayList<>();
        for (String prime : primes) {
            for (int i = 0; i < prime.length(); i++) {
                char c = prime.charAt(i);
                if (!candidates.get(i).contains(c)) {
                    toRemove.add(prime);
                }
            }
        }
        for (String prime : toRemove) {
            primes.remove(prime);
        }
    }
}