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 = "lycanthropy";

    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 Edge {
        int from, to;
        int id;

        Edge(int from, int to, int id) {
            this.from = from;
            this.to = to;
            this.id = id;
        }
    }

    void go() throws InteractorException {
        int n = fin.nextInt();
        int m = fin.nextInt();
        int k = fin.nextInt();
        ArrayList<Edge>[] g = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            g[i] = new ArrayList<>();
        }
        int[] a = new int[m];
        int[] b = new int[m];
        for (int i = 0; i < m; i++) {
            a[i] = fin.nextInt();
            b[i] = fin.nextInt();
        }

        stdout.println(n + " " + m + " " + k);
        for (int i = 0; i < m; i++) {
            stdout.println(a[i] + " " + b[i]);
        }
        stdout.flush();

        Edge[] edges = new Edge[m + 1];
        for (int i = 0; i < m; i++) {
            Edge e = new Edge(a[i] - 1, b[i] - 1, i + 1);
            g[a[i] - 1].add(e);
            edges[i + 1] = e;
        }

        Boolean[] win = new Boolean[n];
        Integer[] loseRank = new Integer[n];
        for (int i = 0; i < n; i++) {
            if (g[i].size() <= k) {
                win[i] = false;
                loseRank[i] = 0;
            }
        }
        win[n - 1] = true;
        for (int i = n - 1; i >= 0; i--) {
            if (win[i] == null) {
                int winCnt = 0;
                for (Edge e : g[i]) {
                    if (win[e.to]) {
                        winCnt++;
                    }
                }
                win[i] = winCnt > k;
                if (!win[i]) {
                    ArrayList<Integer> ranks = new ArrayList<>();
                    for (Edge e : g[i]) {
                        if (win[e.to]) {
                            ranks.add(n);
                        } else {
                            ranks.add(loseRank[e.to]);
                        }
                    }
                    Collections.sort(ranks, new Comparator<Integer>() {
                        @Override
                        public int compare(Integer i1, Integer i2) {
                            return i2.compareTo(i1);
                        }
                    });
                    loseRank[i] = ranks.get(k) + 1;
                }
            }
        }

//        System.err.println(Arrays.toString(win));

        boolean start = true;
        int v = 0;

        int steps = 0;

        while (true) {
            steps++;
            String s = stdin.next().toLowerCase();
            if (s.equals("no")) {
                if (!start) {
                    pe.e("NO not in first line");
                }
                if (win[0]) {
                    ok.e("NO solution");
                } else {
                    wa.e("Solutions exists, but was not found by participant");
                }
            }
            start = false;

            int p = -1;
            try {
                p = Integer.parseInt(s);
            } catch (NumberFormatException e) {
                pe.e("Integer expected, <" + s + "> found");
            }
            if (!(0 <= p && p <= k)) {
                wa.e("# of blocked synapses out of range: " + p + "\\notin [0.." + k + "]");
            }

            Set<Integer> blocked = new HashSet<>();
            for (int i = 0; i < p; i++) {
                int id = stdin.nextInt();
                if (!(1 <= id && id <= m)) {
                    wa.e("# of synapse out of range: " + id + " \\notin [1.." + m + "]");
                }
                if (blocked.contains(id)) {
                    wa.e("repeated synapse #: " + id);
                }
                blocked.add(id);
            }

//            System.err.println("blocked:");
//            for (int i : blocked) {
//                System.err.println(edges[i].from + "->" + edges[i].to + " (" + i + ")");
//            }

            Integer best = null;
            for (Edge e : g[v]) {
                if (blocked.contains(e.id)) {
                    continue;
                }
                if (win[e.to]) {
                    wa.e("I can win");
                }
                if (best == null) {
                    best = e.to;
                }
                if (loseRank[e.to] > loseRank[best]) {
                    best = e.to;
                }
            }
            if (best == null) {
                stdout.println("-1");
                stdout.flush();
                ok.e("ok after " + steps + " steps");
            }
            stdout.println(best + 1);
            stdout.flush();
            v = best;
        }

    }

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

}
