#include <bits/stdc++.h>
using namespace std;
constexpr int max_n=600,max_m=4000000;
vector<int>stk[max_n+1];
int tl[max_n+1];
int a[max_m+1];
int main(){
	FILE*fin=fopen("meow.in","r"),*fout=fopen("meow.out","r");
	int t;
	fscanf(fin,"%d",&t);
	bool flg=1;
	for(int a=1; a<=t; ++a){
		int n,m,k;
		fscanf(fin,"%d%d%d",&n,&m,&k);
		for(int i=1; i<=m; ++i)
			fscanf(fin,"%d",::a+i);
		for(int i=1; i<=n; ++i)
			stk[i].clear(),tl[i]=0;
		int q,now=0;
		fscanf(fout,"%d",&q);
		for(int i=1,op,u,v; i<=q; ++i){
			fscanf(fout,"%d%d",&op,&u);
			if(op==1){
				++now;
				if(now>m){
					fprintf(stderr,"ERROR[4]: opt %d (testcase %d): 1 %d\n",i,a,u);
					flg=0;
					break;
				}
				if(stk[u].size()==tl[u]){
					stk[u].emplace_back(::a[now]);
					continue;
				}
				if(stk[u].back()==::a[now])
					stk[u].pop_back();
				else
					stk[u].emplace_back(::a[now]);
			}
			else{
				fscanf(fout,"%d",&v);
				if(stk[u].size()==tl[u]||stk[v].size()==tl[v]){
					fprintf(stderr,"ERROR: opt %d (testcase %d): 2 %d %d\n",i,a,u,v);
					flg=0;
					break;
				}
				if(stk[u][tl[u]]!=stk[v][tl[v]]){
					fprintf(stderr,"ERROR[2]: opt %d (testcase %d): 2 %d %d\n",i,a,u,v);
					flg=0;
					break;
				}
				++tl[u],++tl[v];
			}
		}
		if(now!=m)
			fprintf(stderr,"ERROR[5]: now %d(testcase %d)\n",now,a),flg=0;
		for(int i=1; i<=n; ++i)
			if(stk[i].size()!=tl[i])
				fprintf(stderr,"ERROR[3]: stack %d(testcase %d)\n",i,a),flg=0;
		fprintf(stderr,"finish %d\n",a);
	}
	if(flg){
		fprintf(stderr,"AC\n");
		return 0;
	}
	return 1;
}