#include<cstdio> #include<cstring> const int maxn=1e6+5; 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=1; while(scanf("%d%d",&n,&m)!=EOF){ for(int i=0;i<n;i++){ scanf("%s",pic+m*i); //for(int j=0;j<m;j++) // printf("%c ",*(pic+m*i+j)); r[i]=i; } for(int j=0;j<m;j++) c[j]=j; scanf("%d",&T); printf("Case #%d: ",t++); while(T--){ scanf("%d%d%d",&op,&x,&y); if(op==1){ int pos=r[x-1]*m+c[y-1]; if(pic[pos]=='T') printf("Tree "); else if(pic[pos]=='i') printf("Phone "); else printf("Empty "); } else if(op==2) Swap(r[x-1],r[y-1]); else Swap(c[x-1],c[y-1]); } } }