#include<set>
#include<deque>
#include<cstdio>
#include<cstdlib>
#include<assert.h>
#include<algorithm>
#define db double
#define pc putchar
#define gc getchar
#define ll long long
#define Tp template<typename _T>
#define Me(a,b) memset(a,b,sizeof(a))
Tp _T mabs(_T x){ return x>0?x:-x; }
Tp _T mmin(_T x,_T y){ return x<y?x:y; }
Tp _T mmax(_T x,_T y){ return x<y?y:x; }
Tp void mswap(_T &x,_T &y){ _T t=x; x=y; y=t; return; }
Tp void print(_T x){ if(x<0) pc('-'),x=-x; if(x>9) print(x/10); pc(x%10+48); return; }
#define maxn
#define maxm
#define MOD
using namespace std;
#define Type int
Type read(){
	Type sum=0; char c=gc(); int flag=0;
	while(c!='-'&&(c<'0'||c>'9')) c=gc();
	if(c=='-') flag=1,c=gc();
	while('0'<=c&&c<='9') sum=(sum<<1)+(sum<<3)+(c^48),c=gc();
	if(flag) return -sum; else return sum;
}
FILE *ouf=fopen("meow.out","r");
int n,m,k,a[2000039];
deque<int> st[339];
void ins(int x,int pos){
	if(st[pos].empty()) st[pos].push_back(x);
	else if(st[pos].back()==x){ st[pos].pop_back(); }
	else st[pos].push_back(x);
	return;
}
int T,opt,x,y;
#define INF 0x7fffffff
void work(){
	n=read(); m=read(); k=read(); int i; for(i=1;i<=m;i++) a[i]=read();
	fscanf(ouf,"%d",&T); i=1;
	while(T--){
		fscanf(ouf,"%d%d",&opt,&x);
		assert(1<=x&&x<=n);
		assert(opt==1||opt==2);
		if(opt==1) ins(a[i],x),i++;
		else if(opt==2){
			fscanf(ouf,"%d",&y); assert(1<=y&&y<=n);
			if(st[x].front()!=st[y].front()){
				puts("INVALID 1"); exit(3);
			} else st[x].pop_front(),st[y].pop_front();
		}
	} for(i=1;i<=n;i++) if(!st[i].empty()){ puts("INVALID 2"); exit(3); }
}
int main(){
	system("tmp < meow4.in > meow.out");
	freopen("meow4.in","r",stdin);
	int T=read(); while(T--) work(); puts("OK"); return 0;
}
//NOIP or CodeForces???