import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.Random;
import java.util.Scanner;
import java.util.StringTokenizer;

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

    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);
        }
    };

    void go() throws InteractorException {
        String strategyName = fin.next().toLowerCase();
        int seed = fin.nextInt();
        int n = fin.nextInt();
        int m = fin.nextInt();

        System.out.println(n + " " + m);
        System.out.flush();

        Strategy strategy = null; // :(
        switch (strategyName) {
            case "random":
                strategy = new RandomStrategy(new Random(seed));
                break;
            case "flow":
                strategy = new MaxFlowStrategy();
                break;
            default:
                fail.e("I don't know strategy \"" + strategyName + "\"");
        }

        GameState game = new GameState(n, m);
        int maxSteps = (n * m + 1) / 2;
        for (int it = 0; it < maxSteps + 1; it++) {
            String user = stdin.nextLine();
            if (user.equals("x_X")) {
                if (game.isWinningPositionForBadGuys()) {
                    ok.e("ok after " + it + " turns");
                } else {
                    wa.e("pichal'ka");
                }
            }
            StringTokenizer st = new StringTokenizer(user);
            if (st.countTokens() != 2) {
                pe.e("User input is not two numbers: " + st.countTokens() + " tokens");
            }
            int x = 0, y = 0; // :(
            try {
                x = Integer.parseInt(st.nextToken()) - 1;
                y = Integer.parseInt(st.nextToken()) - 1;
            } catch (NumberFormatException e) {
                pe.e("Not a number :(");
            }
            if (!(0 <= x && x < n)) {
                wa.e("x out of bounds: " + (x + 1) + " not in [1; " + n + "]");
            }
            if (!(0 <= y && y < m)) {
                wa.e("y out of bounds: " + (y + 1) + " not in [1; " + m + "]");
            }
            if (game.field[x][y] != GameState.Cell.FREE) {
                wa.e("cell is not free: f[" + (x + 1) + "][" + (y + 1) + "] = " + game.field[x][y]);
            }
            game.set(x, y, GameState.Cell.BAD);
            int[] juryTurn = strategy.turn(game);
            game.set(juryTurn[0], juryTurn[1], GameState.Cell.GOOD);
            System.out.println((juryTurn[0] + 1) + " " + (juryTurn[1] + 1));
            System.out.flush();
        }
        wa.e("out of steps");
    }

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

    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);
    }

    void close() {
        fin.close();
        fout.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.println(e.getClass().getSimpleName());
            instance.fout.println(e.getMessage());
        } catch (NumberFormatException e) {
            instance.fout.println("PE");
            instance.fout.println(e.getMessage());
        } catch (IOException e) {
            instance.fout.println("FAIL");
            instance.fout.println(e.getMessage());
        } catch (Exception e) {
            instance.fout.println("FAIL");
            instance.fout.println("Something went wrong: " + e.getMessage());
        }
        instance.close();
    }

}
