import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < t; i++) { String[] sa = br.readLine().split(" "); int k = Integer.parseInt(sa[0]); long z = Long.parseLong(sa[1]); long c = Long.parseLong(sa[2]); sa = br.readLine().split(" "); long[] a = new long[k]; for (int j = 0; j < k; j++) { a[j] = Integer.parseInt(sa[j]); } sa = br.readLine().split(" "); long[] p = new long[k]; for (int j = 0; j < k; j++) { p[j] = Integer.parseInt(sa[j]); } long g = 0; for (int j = 0; j < k; j++) { long b = a[j] % (p[j] + 1); g ^= b; } if (g > 0) { c -= g; } if (z > c) { pw.println('Z'); } else { pw.println('C'); } } br.close(); pw.flush(); } }