
#ifdef BURUNDUK
#  include "my_testlib.h"
#else
#  include "testlib.h"
#endif

#define forn(i, n) for (int i = 0; i < (int)(n); i++)
#define fill(a, x) memset(a, x, sizeof(a))

typedef long long ll;

const int N = 2e5;           

int n, m, a[N], b[N], ud[N], ue[N];

void readInput( InStream &in ) {
/**
	m := inf.readlongint;
	n := inf.readlongint;
	for i := 1 to m do
		a[i] := inf.readlongint;
	for i := 1 to n do
		b[i] := inf.readlongint;
*/
  m = in.readInt(1, N);
  n = in.readInt(1, N);
  forn(i, m)
    a[i] = in.readInt();
  forn(i, n)
    b[i] = in.readInt();
}

int checkOutput( InStream &out ) {
/**
	for i := 1 to pa do begin
		d := ouf.readlongint;
		e1 := ouf.readlongint;
		e2 := ouf.readlongint;

		if (d < 1) or (d > m) then
			quit(_wa, format('invalid deer number: %d', [d]));
		if (e1 < 1) or (e1 > n) then
			quit(_wa, format('invalid elf number: %d', [d]));
		if (e2 < 1) or (e2 > n) then
			quit(_wa, format('invalid elf number: %d', [d]));
		if ud[d] then
			quit(_wa, format('deer used twice: %d', [d]));
		ud[d] := true;
		if ue[e1] then
			quit(_wa, format('elf used twice: %d', [e1]));
		ue[e1] := true;
		if ue[e2] then
			quit(_wa, format('elf used twice: %d', [e2]));
		ue[e2] := true;

		if not ((b[e1] < a[d]) and (a[d] < b[e2])) then
			quit(_wa, format('elves %d (%d) and %d (%d) cannot ride deer %d (%d)', [e1, b[e1], e2, b[e2], d, a[d]]));
	end;
 */
  int pa = out.readInt();
  fill(ud, 0);
  fill(ue, 0);
  forn(i, pa) {
    int d = out.readInt(1, m) - 1;
    int e1 = out.readInt(1, n) - 1;
    int e2 = out.readInt(1, n) - 1;
    if (ud[d]++)  out.quitf(_wa, "deer used twice: %d\n", d + 1);
    if (ue[e1]++) out.quitf(_wa, "elf used twice: %d\n", e1 + 1);
    if (ue[e2]++) out.quitf(_wa, "elf used twice: %d\n", e2 + 1);
    if (!(b[e1] < a[d] && a[d] < b[e2])) 
      out.quitf(_wa, "elves %d (%d) and %d (%d) cannot ride deer %d (%d)", e1 + 1, b[e1], e2 + 1, b[e2], d + 1, a[d]);
  }
  return pa;
}

int main(int argc, char *argv[]) {
  registerTestlibCmd(argc, argv);

  readInput(inf);

  int ja = checkOutput(ans);
  int ca = checkOutput(ouf);

  if (ca != ja)
    quitf(ca > ja ? _fail : _wa, "Contestant says %d, jury say %d", ca, ja);
  quitf(_ok, "OK (m = %d, n = %d, answer = %d)", m, n, ja);
  return 0;
}
