#include<iostream>
#include<cstdio>
#include<cstring>
#include<map>
using namespace std;
typedef struct node{
int x,y;
bool operator<(const node &b)const
{
if(x==b.x)
return y<b.y;
else
return x<b.x;
}
}node;
int main() {
map<node,int>ma;
map<int,int>f,ff;
node e;
int n,m,i,j,k,t,id,idd,ss,s,num=0;
scanf("%d",&t);
while(t--) {
scanf("%d%d%d",&n,&m,&k);
id=0;idd=0;
while(k--) {
scanf("%d%d%d",&i,&j,&s);
if(f[i]==0)
f[i]=++id;
if(ff[j]==0)
ff[j]=++idd;
e.x=f[i];
e.y=ff[j];
ma[e]=s;
}
scanf("%d",&j);
printf("Case #%d:\n",++num);
while(j--) {
scanf("%d",&i);
if(i==1) {
scanf("%d%d",&id,&idd);
ss=f[id];
f[id]=f[idd];
f[idd]=ss;
}
if(i==2) {
scanf("%d%d",&id,&idd);
ss=ff[id];
ff[id]=ff[idd];
ff[idd]=ss;
}
if(i==3) {
scanf("%d%d",&id,&idd);
e.x=f[id];
e.y=ff[idd];
// printf("%d %d\n",f[id],ff[idd]);
printf("%d\n",ma[e]);
}
}
}
return 0;
}
05-16 02:28