import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

public class Interact {
    private static final String fileName = "valhalla";

    static Random rnd;

    static abstract class InteractorException extends Exception {
        InteractorException(String s) {
            super(s);
        }
    }

    static class WA extends InteractorException {
        WA(String s) {
            super(s);
        }
    }

    static class OK extends InteractorException {
        OK(String s) {
            super(s);
        }
    }

    static class PE extends InteractorException {
        PE(String s) {
            super(s);
        }
    }

    static class FAIL extends InteractorException {
        FAIL(String s) {
            super(s);
        }
    }

    static interface E {
        InteractorException e(String s) throws InteractorException;
    }

    static final E wa = new E() {
        @Override
        public InteractorException e(String s) throws WA {
            throw new WA(s);
        }
    };

    static final E pe = new E() {
        @Override
        public InteractorException e(String s) throws PE {
            throw new PE(s);
        }
    };

    static final E fail = new E() {
        @Override
        public InteractorException e(String s) throws FAIL {
            throw new FAIL(s);
        }
    };

    static final E ok = new E() {
        @Override
        public InteractorException e(String s) throws InteractorException {
            throw new OK(s);
        }
    };

    public static char[][][] FIGURES = {
            {
                    "###".toCharArray()
            },
            {
                    "##".toCharArray()
            },
            {
                    "#.".toCharArray(),
                    "##".toCharArray()
            }
    };

    static char[][] deepClone(char[][] a) {
        char[][] res = new char[a.length][];
        for (int i = 0; i < res.length; i++) {
            res[i] = a[i].clone();
        }
        return res;
    }

    static class Field {
        final char[][] f;

        Field(int x, int y) {
            f = new char[y][x];
            for (char[] fx : f) {
                Arrays.fill(fx, '.');
            }
        }

        Field(char[][] f) {
            this.f = f;
        }

        Field update(char[][] figure, int pos) {
            int h = f.length - 1;
            char[][] f = deepClone(this.f);
            outer: for (; h >= figure.length - 1; h--) {
                for (int i = 0; i < figure.length; i++) {
                    for (int j = 0; j < figure[i].length; j++) {
                        if (figure[i][j] == '#' && f[h - i][pos + j] == '#') {
                            break outer;
                        }
                    }
                }
            }
            h++;
            for (int i = 0; i < figure.length; i++) {
                for (int j = 0; j < figure[i].length; j++) {
                    if (figure[i][j] == '#') {
                        f[h - i][pos + j] = '#';
                    }
                }
            }

            for (int i = 0; i < f.length; i++) {
                boolean all = true;
                for (int j = 0; j < f[i].length; j++) {
                    all &= f[i][j] == '#';
                }
                if (all) {
                    for (int k = i + 1; k < f.length; k++) {
                        f[k - 1] = f[k].clone();
                    }
                    i--;
                }
            }
            return new Field(f);
        }

        int score() {
            int res = 0;
            for (char[] fx : f) {
                for (char x : fx) {
                    res += x == '#' ? 1 : 0;
                }
            }
            return res;
        }

        @Override
        public String toString() {
            StringBuilder sb = new StringBuilder();
            for (int i = f.length - 1; i >= 0; i--) {
                sb.append(new String(f[i])).append("\n");
            }
            return sb.toString();
        }
    }

    static char[][] rotate(char[][] fig) {
        int n = fig.length;
        int m = fig[0].length;
        char[][] res = new char[m][n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                res[j][n - 1 - i] = fig[i][j];
            }
        }
        return res;
    }

    static interface Strategy {
        int turn(Field f);
    }

    static Strategy forName(String s) {
        switch (s) {
            case "Const1": return new Strategy() {
                @Override
                public int turn(Field f) {
                    return 1;
                }
            };
            case "Const2": return new Strategy() {
                @Override
                public int turn(Field f) {
                    return 2;
                }
            };
            case "Const3": return new Strategy() {
                @Override
                public int turn(Field f) {
                    return 3;
                }
            };
            case "Random": return new Strategy() {
                @Override
                public int turn(Field f) {
                    return rnd.nextInt(3) + 1;
                }
            };
            default: throw new AssertionError("Unknown strategy: <" + s + ">");
        }
    }

    void go() throws InteractorException {
        String strat = fin.next();
        int n = fin.nextInt();
        Strategy s = forName(strat);
        int seed = fin.nextInt();
        rnd = new Random(seed);
        stdout.println(n);
        Field f = new Field(3, 20);
        stdout.flush();
        for (int i = 0; i < n; i++) {
            int turn = s.turn(f);
            stdout.println(turn);
            stdout.flush();
            int t = stdin.nextInt();
            int pos = stdin.nextInt() - 1;
            if (!(0 <= t && t < 4)) {
                pe.e("Rotates must be int from 0 to 3, " + t + " found");
            }
            char[][] fig = FIGURES[turn - 1];
            for (int j = 0; j < t; j++) {
                fig = rotate(fig);
            }
            try {
                f = f.update(fig, pos);
            } catch (IndexOutOfBoundsException e) {
                pe.e("Bad position for figure " + turn + " : " + pos);
            }
            if (f.score() > 15) {
                wa.e(f.score() + " meat pieces on table");
            }
        }
        ok.e("ok");
    }

    final Scanner stdin;
    final Scanner fin;
    final PrintWriter fout;
    final PrintWriter stdout;

    Interact(String inputFileName, String outputFileName) throws IOException {
        stdin = new Scanner(System.in);
        fin = new Scanner(new FileReader(inputFileName));
        fout = new PrintWriter(new FileWriter(outputFileName), true);
        stdout = new PrintWriter(System.out);
    }

    void close() {
        fin.close();
        fout.close();
        stdout.close();
    }

    public static void main(String[] args) {
        Locale.setDefault(Locale.US);
        Interact instance = null;
        try {
            instance = new Interact(
                    args.length >= 2 ? args[0] : fileName + ".in",
                    args.length >= 2 ? args[1] : fileName + ".out");
            instance.go();
        } catch (InteractorException e) {
            instance.fout.print(e.getClass().getSimpleName() + " ");
            instance.fout.println(e.getMessage());
        } catch (NumberFormatException e) {
            instance.fout.print("PE ");
            instance.fout.println(e.getMessage());
        } catch (IOException e) {
            instance.fout.print("FAIL ");
            instance.fout.println(e.getMessage());
        } catch (Exception e) {
            instance.fout.print("FAIL ");
            instance.fout.println("Something went wrong: " + e.getMessage());
        }
        instance.close();
    }

}
