#include<stdio.h> #include<queue> #include<iostream> #include<string.h> #include<algorithm> #define N 200 using namespace std; struct node { int x,y,time; }start,end,cur,next; char map[N][N]; int visit[N][N][N],k,r,c; int dis[4][2]={{1,0},{-1,0},{0,-1},{0,1}}; int judge(int a,int b,int ti) { if(visit[a][b][ti%k]) return 0; if(a<1||a>r||b<1||b>c) return 0; if(map[a][b]=='#'&&ti%k!=0) return 0; return 1; } int bfs(node start) { int i; memset(visit,0,sizeof(visit)); queue<node>q; start.time=0; visit[start.x][start.y][0]=1; q.push(start); while(!q.empty()) { cur=q.front(); q.pop(); for(i=0;i<4;i++) { next.x=cur.x+dis[i][0]; next.y=cur.y+dis[i][1]; next.time=cur.time+1; if(judge(next.x,next.y,next.time)) { if(next.x==end.x&&next.y==end.y) return next.time; visit[next.x][next.y][next.time%k]=1; q.push(next); } } } return -1; } int main() { int i,j,t,ans; scanf("%d",&t); while(t--) { scanf("%d%d%d",&r,&c,&k); for(i=1;i<=r;i++) scanf("%s",map[i]+1); for(i=1;i<=r;i++) for(j=1;j<=c;j++) { if(map[i][j]=='Y') { start.x=i; start.y=j; } if(map[i][j]=='G') { end.x=i; end.y=j; } } ans=bfs(start); if(ans==-1) printf("Please give me another chance! "); else printf("%d ",ans); } return 0; }