#include<bits/stdc++.h>
#ifdef xay5421
#define D(...) fprintf(stderr,__VA_ARGS__)
#else
#define D(...) ((void)0)
#endif
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
#define each(x,v) for(auto&x:v)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
using namespace std;
using LL=long long;
template<class T>void rd(T&x){
	int f=0,c;
	while(!isdigit(c=getchar()))f^=!(c^45);
	x=(c&15);
	while(isdigit(c=getchar()))x=x*10+(c&15);
	if(f)x=-x;
}
int n,m,K,T,a[2000005];
vector<int>v[305];
int main(){
	ifstream in("meow.in");
	ifstream out("meow.out");
	in>>T;
	while(T--){
		in>>n>>m>>K;
		rep(i,1,n)v[i].clear();
		rep(i,1,m)in>>a[i],assert(1<=a[i]&&a[i]<=K);
		int len;
		out>>len;
		int pos=0;
		assert(m<=len&&len<=m*2);
		rep(i,1,len){
			int opt;
			out>>opt;
			if(opt==1){
				int x;
				out>>x;
				assert(1<=x&&x<=n);
				++pos;
				if(!v[x].empty()&&v[x].back()==a[pos]){
					v[x].pop_back();
				}else{
					v[x].push_back(a[pos]);
				}
			}else{
				int x,y;
				out>>x>>y;
				assert(1<=x&&x<=n);
				assert(1<=y&&y<=n);
				assert(x!=y);
				assert(!v[x].empty()&&!v[y].empty());
				assert(v[x][0]==v[y][0]);
				if(v[x][0]==v[y][0]){
					v[x].erase(v[x].begin());
					v[y].erase(v[y].begin());
				}
			}
		}
		rep(i,1,n)assert(v[i].empty());
	}
	return 0;
}
