#include #include #include using namespace std; char map[105][105]; int sx,sy,n,m; int visit[105][105]; int dir[4][2]= {1,0,0,1,-1,0,0,-1}; struct node { int x; int y; int cost; } a[1000015]; int mvCost(int tx,int ty,int cost) { if(map[tx][ty]=='R') cost-=3; else if(map[tx][ty]=='T') cost-=2; else cost-=1; int flag=0; for(int i=0;i<4;i++) { int ttx=tx+dir[i][0]; int tty=ty+dir[i][1]; if(ttx>=0 && ttx=0 && tty0) cost=0; return cost; } void bfs(int mv) { memset(visit,-1,sizeof(visit)); a[0].x=sx; a[0].y=sy; a[0].cost=mv; visit[sx][sy]=mv; int start=0,end=1; node cur,change; while(start=0 && tx=0 && tyvisit[tx][ty]) { change.x=tx; change.y=ty; change.cost=Cost; a[end++]=change; visit[tx][ty]=Cost; if(map[tx][ty]!='P') map[tx][ty]='*'; } } } } } } int main() { int t,mv; cin>>t; while(t--) { cin>>n>>m>>mv; for(int i=0; i>map[i][j]; if(map[i][j]=='Y') { sx=i; sy=j; } } } bfs(mv); for(int i=0; i