import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.util.Collection; import java.util.HashMap; import java.util.InputMismatchException; import java.io.IOException; import java.util.HashSet; import java.io.Writer; import java.io.OutputStreamWriter; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); OutputWriter out = new OutputWriter(outputStream); meetup solver = new meetup(); solver.solve(1, in, out); out.close(); } static class meetup { public InputReader in; public OutputWriter out; public HashMap> g1; public HashMap> g2; public HashSet s1; public HashSet s2; public int n; public int m; public int ka; public int kb; public void solve(int testNumber, InputReader in, OutputWriter out) { this.in = in; this.out = out; n = in.nextInt(); m = in.nextInt(); ka = in.nextInt(); kb = in.nextInt(); g1 = new HashMap<>(); g2 = new HashMap<>(); s1 = new HashSet<>(); s2 = new HashSet<>(); read(g1, s1, ka); read(g2, s2, kb); while (true) { int sz = g1.size(); String q = null; for (String s : g1.keySet()) { if (s1.contains(s) && g1.get(s).size() * 2 < sz) { q = s; break; } } if (q != null) { ask1(q, sz == 1); continue; } for (String s : g2.keySet()) { if (s2.contains(s) && g2.get(s).size() * 2 >= sz) { q = s; break; } } if (q != null) { ask2(q, sz == 1); continue; } answer("No"); } } public void read(HashMap> g, HashSet s, int l) { for (int i = 0; i < n; i++) { String w = in.next(); g.put(w, new HashSet<>()); if (i < l) s.add(w); } for (int i = 0; i < m; i++) { String a = in.next(), b = in.next(); g.get(a).add(b); g.get(b).add(a); } } public void ask1(String q, boolean last) { out.println("A " + q); out.flush(); String rs = in.next(); if (s2.contains(rs)) { answer("Yes"); } else { if (last) answer("No"); reduce(g1, q, false); reduce(g2, rs, false); } } public void ask2(String q, boolean last) { out.println("B " + q); out.flush(); String rs = in.next(); if (s1.contains(rs)) { answer("Yes"); } else { if (last) answer("No"); reduce(g1, rs, true); reduce(g2, q, true); } } public void answer(String resp) { out.println("C " + resp); out.flush(); out.close(); System.exit(0); } public void reduce(HashMap> g, String root, boolean conn) { g.keySet().removeIf(x -> !x.equals(root) && (conn == g.get(root).contains(x))); g.values().forEach(v -> v.removeIf(x -> !g.containsKey(x))); } } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (this.numChars == -1) { throw new InputMismatchException(); } else { if (this.curChar >= this.numChars) { this.curChar = 0; try { this.numChars = this.stream.read(this.buf); } catch (IOException var2) { throw new InputMismatchException(); } if (this.numChars <= 0) { return -1; } } return this.buf[this.curChar++]; } } public int nextInt() { int c; for (c = this.read(); isSpaceChar(c); c = this.read()) { ; } byte sgn = 1; if (c == 45) { sgn = -1; c = this.read(); } int res = 0; while (c >= 48 && c <= 57) { res *= 10; res += c - 48; c = this.read(); if (isSpaceChar(c)) { return res * sgn; } } throw new InputMismatchException(); } public String next() { int c; while (isSpaceChar(c = this.read())) { ; } StringBuilder result = new StringBuilder(); result.appendCodePoint(c); while (!isSpaceChar(c = this.read())) { result.appendCodePoint(c); } return result.toString(); } public static boolean isSpaceChar(int c) { return c == 32 || c == 10 || c == 13 || c == 9 || c == -1; } } static class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void print(Object... objects) { for (int i = 0; i < objects.length; i++) { if (i != 0) { writer.print(' '); } writer.print(objects[i]); } } public void println(Object... objects) { print(objects); writer.println(); } public void close() { writer.close(); } public void flush() { writer.flush(); } } }