#include<cstdio>
#include<cstring>
const int maxn=1e6+;
using namespace std;
int r[maxn],c[maxn];
char pic[maxn];
void Swap(int &x,int &y)
{
int temp=x;
x=y;
y=temp;
}
int main()
{
int n,m,op,x,y,T,t=;
while(scanf("%d%d",&n,&m)!=EOF){
for(int i=;i<n;i++){
scanf("%s",pic+m*i);
//for(int j=0;j<m;j++)
// printf("%c\n",*(pic+m*i+j));
r[i]=i;
}
for(int j=;j<m;j++)
c[j]=j;
scanf("%d",&T);
printf("Case #%d:\n",t++);
while(T--){
scanf("%d%d%d",&op,&x,&y);
if(op==){
int pos=r[x-]*m+c[y-];
if(pic[pos]=='T')
printf("Tree\n");
else if(pic[pos]=='i')
printf("Phone\n");
else
printf("Empty\n");
}
else if(op==)
Swap(r[x-],r[y-]);
else
Swap(c[x-],c[y-]);
}
}
}