#include<bits/stdc++.h>
template<typename _Tp>void read(_Tp &x){
	char ch(getchar());bool f=0;while(!isdigit(ch))f|=ch=='-',ch=getchar();
	x=ch&15,ch=getchar();while(isdigit(ch))x=x*10+(ch&15),ch=getchar();
	if(f)x=-x;
}
const int TT=1015;
int N[TT],M[TT],K[TT];std::vector<int> a[TT];
std::deque<int> b[305];
void push(int x,int y){
	if(!b[x].empty()&&b[x].back()==y)b[x].pop_back();
	else b[x].push_back(y);
}
void apply(int x,int y){
	assert(!b[x].empty()&&!b[y].empty()&&b[x].front()==b[y].front());
	b[x].pop_front(),b[y].pop_front();
}
int main(){
	freopen("meow.in","r",stdin);
	int T;read(T);
	for(int i=1;i<=T;++i){
		read(N[i]),read(M[i]),read(K[i]);
		a[i].resize(M[i]);for(int j=0;j<M[i];++j)read(a[i][j]);
	}
	freopen("meow.out","r",stdin);
	for(int _=1;_<=T;++_){
		int n=N[_],m=M[_],k=K[_],len;read(len);int opt,x,y,p=0;
		for(int i=1;i<=n;++i)b[i].clear();
		for(int t=0;t<len;++t){
			read(opt),read(x);
			if(opt==1){
				push(x,a[_][p++]);
			}
			else if(opt==2){
				read(y);
				apply(x,y);
			}
		}
		for(int i=1;i<=n;++i){
			if(!b[i].empty()){
				for(auto it:b[i])fprintf(stderr,"%d ",it);
				fprintf(stderr,"\n");
			}
		}
		for(int i=1;i<=n;++i)assert(b[i].empty());
//		fprintf(stderr,"Pass\n");
	}
	return 0;
}
