#include <bits/stdc++.h>
using namespace std;
int T, n, m, k, c, p, a[2000006], s1, s2, o; deque <int> q[305];
int main() {
	ifstream in ("meow2.in");
	ifstream out("meow.out");
	in >> T;
	while (T --) {
		in >> n >> m >> k;
		for (int i=1; i<=m; i++) in >> a[i];
		out >> c, p = 0;
		assert (m <= c && c <= m << 1);
		while (c --) {
			out >> o;
			if (o & 1) {
				out >> s1, p ++;
				assert (1 <= s1 && s1 <= n);
				if (! q[s1]. empty() && q[s1]. back() == a[p]) q[s1]. pop_back();
				else q[s1]. push_back(a[p]);
			} else {
				out >> s1 >> s2;
				assert (1 <= s1 && s1 <= n);
				assert (1 <= s2 && s2 <= n);
				assert (s1 != s2);
				assert (! q[s1]. empty() && ! q[s2]. empty());
				assert (q[s1]. front() == q[s2]. front());
				q[s1]. pop_front(), q[s2]. pop_front();
			}
		} assert (p == m);
		for (int i=1; i<=n; i++)
			assert (q[i]. empty());
		puts ("OK");
	}
}