ll h,w,q,x,y,xx=-1,yy=-1; Mint a1[1d5],b1[1d5],c1[1d5],d1=1,t1; Mint a2[1d5],b2[1d5],c2[1d5],d2=1,t2; { rd(h,w,a1(h*w),q); b1[0..h-1]=1; c1[0..w-1]=1; b2[0..h-1]=1; c2[0..w-1]=1; rep(y,h)rep(x,w){ if(a1[x+w*y]){ a2[x+w*y]=a1[x+w*y]; }else{ a1[x+w*y]=1; a2[x+w*y]=2; } (b1[y],c1[x],d1)*=a1[x+w*y]; (b2[y],c2[x],d2)*=a2[x+w*y]; } rep(q){ rd(y--,x--); t1=d1*a1[x+w*y]/b1[y]/c2[x]; t2=d2*a2[x+w*y]/b2[y]/c2[x]; wt(t1==t2?int(t1):0); } }