ll h,w,q,x,y,xx=-1,yy=-1; Mint a[1d5],b[1d5],c[1d5],d=1,t; { rd(h,w,a(h*w),q); b[0..h-1]=1; c[0..w-1]=1; rep(y,h)rep(x,w){ t=a[x+w*y]; if(t){ (b[y],c[x],d)*=a[x+w*y]; }else{ xx=xx==x||xx==-1?x:-2; yy=yy==y||yy==-1?y:-2; } } rep(q){ rd(y--,x--); if((xx==x||xx==-1)&&(yy==y||yy==-1)){ wt(d*a[x+w*y]/b[y]/c[x]); }else{ wt(0); } } }