#include<bits/stdc++.h>
std::deque<int> qq[605];
int t,n,m,k,q,f[200005];
int main()
{
	freopen("sb.in","r",stdin);
//	freopen("meow.out","w",stdout);
	scanf("%d",&t);
	while (t--)
	{
		scanf("%d%d%d",&n,&m,&k);
		for (int i=1;i<=m;i++) scanf("%d",&f[i]);
		freopen("meow.out","r",stdin);
//		for (int i=1;i<=m;i++) printf("%d ",f[i]);puts("");
		int x=0;
		scanf("%d",&q);
		for (int i=1;i<=q;i++)
		{
			int opt;
			scanf("%d",&opt);
			if (opt==1)
			{
				int pos;
				++x;
				scanf("%d",&pos);
				if (qq[pos].size()&&qq[pos].back()==f[x]) qq[pos].pop_back();
				else qq[pos].push_back(f[x]);
			}
			else if (opt==2)
			{
				int p1,p2;
				scanf("%d%d",&p1,&p2);
				assert(qq[p1].size()&&qq[p2].size());
				assert(qq[p1].front()==qq[p2].front());
				qq[p1].pop_front(),qq[p2].pop_front();
			}
		}
		for (int i=1;i<=n;i++) assert(!qq[i].size());
	}
	return 0;
}