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

public class Interact {
    private static final String fileName = "nebuchadnezzar";
    private static final int MAX_STEPS = 5000;

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

    static class Pair {
        int a, b;

        Pair(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public String toString() {
            return "(" + a + ", " + b + ")";
        }
    }

    static boolean inBounds(int a, int n) {
        return 0 <= a && a < n;
    }

    static int ind(boolean b) {
        return b ? 1 : 0;
    }

    static void check(Pair p, int n, E e) throws InteractorException {
        if (!inBounds(p.a, n))
            e.e("fst " + p + " is out of bounds");
        if (!inBounds(p.b, n))
            e.e("snd " + p + " is out of bounds");
        if (p.a == p.b)
            e.e("swapping on same positions: " + p);
    }

    static abstract class Strategy {
        int[] a;
        int[] w;
        int n;
        int correct;
        ArrayList<Pair> contestantTurns;
        ArrayList<Pair> myTurns;

        void init(int[] a) {
            this.a = a.clone();
            n = a.length;
            w = new int[n];
            for (int i = 0; i < n; i++) {
                w[a[i]] = i;
                correct += ind(a[i] == i);
            }
            contestantTurns = new ArrayList<Pair>();
            myTurns = new ArrayList<Pair>();
        }

        void apply(Pair p, E e) throws InteractorException {
            check(p, n, e);
            int tmp = a[p.a];
            a[p.a] = a[p.b];
            a[p.b] = tmp;
            int wereCorrect = ind(w[a[p.a]] == a[p.a]) + ind(w[a[p.b]] == a[p.b]);
            w[a[p.a]] = p.a;
            w[a[p.b]] = p.b;
            int nowCorrect = ind(w[a[p.a]] == a[p.a]) + ind(w[a[p.b]] == a[p.b]);
            correct -= wereCorrect;
            correct += nowCorrect;
        }

        void cTurn(Pair p) throws InteractorException {
            contestantTurns.add(p);
            apply(p, pe);
        }

        void myTurn(Pair p) throws InteractorException {
            myTurns.add(p);
            apply(p, fail);
            print(p);
        }

        boolean isSorted() {
            return correct == n;
        }

        abstract Pair getTurn();

        static Strategy forName(String s) throws InteractorException {
            switch (s) {
                case "Random" : return new RandomStrategy();
                case "Swap12" : return new Swap12();
                case "HelpingHand" : return new HelpingHand();
                case "Spoiler" : return new Spoiler();
                default:
                    fail.e("Strategy not found: \"" + s + "\"");
                    return null;
            }
        }
    }

    static class RandomStrategy extends Strategy {
        @Override
        Pair getTurn() {
            int a = rnd.nextInt(n);
            int b = rnd.nextInt(n);
            int min = Math.min(a, b);
            int max = Math.max(a, b);
            if (a != b) {
                return new Pair(min, max);
            } else {
                return getTurn();
            }
        }
    }

    static class Swap12 extends Strategy {
        @Override
        Pair getTurn() {
            return new Pair(0, 1);
        }
    }

    static class Spoiler extends Strategy {
        @Override
        Pair getTurn() {
            ArrayList<Integer> good = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                if (a[i] == i) {
                    good.add(i);
                }
            }
            if (good.size() == 0) {
                good.add(0);
            }
            if (good.size() == 1) {
                good.add((good.get(0) + 1) % n);
            }
            Pair res = new Pair(good.get(0), good.get(1));
            return res;
        }
    }

    static class HelpingHand extends Strategy {
        @Override
        Pair getTurn() {
            Integer pos = null;
            for (int i = 0; i < n; i++) {
                if (a[i] != i) {
                    pos = i;
                }
            }
            if (pos != null) {
                return new Pair(pos, w[pos]);
            } else {
                return new Pair(0, 1);
            }
        }
    }

    String pp(int[] a) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < a.length; i++) {
            int ai = a[i];
            sb.append(a[i] + 1);
            if (i != a.length - 1) {
                sb.append(" ");
            }
        }
        return sb.toString();
    }

    static void print(Pair p) {
        System.out.println((p.a + 1) + " " + (p.b + 1));
        System.out.flush();
    }

    void go() throws InteractorException {
        String strategyS = fin.nextLine();
        Strategy strategy = Strategy.forName(strategyS);
        int seed = fin.nextInt();
        rnd = new Random(seed);
        int n = fin.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = fin.nextInt();
//        System.err.println(Arrays.toString(a));
        System.out.println(n);
        System.out.println(pp(a));
        System.out.flush();
        strategy.init(a);
        for (int i = 0; i < MAX_STEPS / 2; i++) {
            String line = stdin.nextLine();
//            System.err.println("I'm interactor and I just read <" + line + ">, before that action: " + Arrays.toString(strategy.a));
            if (line.toLowerCase().equals("done")) {
                (strategy.isSorted() ? ok : wa).e("done: " + (2 * i + 1) + " steps " + Arrays.toString(strategy.a));
            }
            String[] ln = line.split(" ");
            if (ln.length != 2) {
                pe.e("can't parse: <" + /*line*/ "" + ">");
            }
            int p1 = Integer.parseInt(ln[0]) - 1;
            int p2 = Integer.parseInt(ln[1]) - 1;
            Pair p = new Pair(p1, p2);
            strategy.cTurn(p);
            line = stdin.nextLine();
//            System.err.println("I'm interactor and I just read <" + line + ">, before that action: " + Arrays.toString(strategy.a));
            if (line.toLowerCase().equals("done")) {
                (strategy.isSorted() ? ok : wa).e("done: " + (2 * i + 2) + " steps " + Arrays.toString(strategy.a));
            }
            ln = line.split(" ");
            if (ln.length != 2) {
                pe.e("can't parse: <" + /*line*/ "" + ">");
            }
            p1 = Integer.parseInt(ln[0]) - 1;
            p2 = Integer.parseInt(ln[1]) - 1;
            p = new Pair(p1, p2);
            strategy.cTurn(p);
            strategy.myTurn(strategy.getTurn());
        }
        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());
            instance.fout.println("There is no spoon");
        } catch (IOException e) {
            instance.fout.println("FAIL");
            //instance.fout.println(e.getMessage());
            instance.fout.println("The cake is a lie");
        } catch (Exception e) {
            instance.fout.println("FAIL");
            instance.fout.println("Something went wrong: " /*+ e.getMessage()*/);
        }
        instance.close();
    }
}
