#include using namespace std; typedef signed long long ll; #undef _P #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) //------------------------------------------------------- const int MAT=400; struct Mat { double v[MAT][MAT]; }; Mat mulmat(Mat& a,Mat& b,int n=MAT) { static Mat r; int x,y,z; FOR(x,n) FOR(y,n) r.v[x][y]=0; FOR(x,n) FOR(z,n) if(a.v[x][z]) FOR(y,n) if(b.v[z][y]) { r.v[x][y] += a.v[x][z]*b.v[z][y]; } return r; } int H,W,Q; string S[404]; int tar[400]; vector to[20][20]; int SY,SX; vector G; void solve() { int i,j,k,l,r,x,y; string s; static Mat m; cin>>H>>W>>Q; FOR(y,H) cin>>S[y]; FOR(y,H) FOR(x,W) tar[y*20+x]=y*20+x; FOR(i,Q) { int X1,Y1,X2,Y2; cin>>Y1>>X1>>Y2>>X2; Y1--,X1--,Y2--,X2--; tar[Y1*20+X1]=Y2*20+X2; tar[Y2*20+X2]=Y1*20+X1; } FOR(y,H) FOR(x,W) { if(S[y][x]=='A') SY=y, SX=x, S[y][x]='O'; if(S[y][x]=='%') G.push_back(y*20+x), S[y][x]='*'; if(S[y][x]=='*') to[y][x].push_back(y*20+x); if(S[y][x]=='O') { if(y && S[y-1][x]!='#') to[y][x].push_back(tar[(y-1)*20+x]); if(y