#include #define int long long using namespace std; const int mod=1000000007; int p(int A,int B){ if(B==0)return 1; if(B%2)return p(A,B-1)*A%mod; int C=p(A,B/2); return C*C%mod; } signed main(){ int H,W,ans=1; cin>>H>>W; vector> A(H,vector(W)); vector B(H,1),C(W,1); for(int i=0;i>A[i][j]; ans=ans*A[i][j]%mod; B[i]=B[i]*A[i][j]%mod; C[j]=C[j]*A[i][j]%mod; } } vector D(0),E(0); for(int i=0;i>Q; if(D.size()>1 && E.size()>1){ while(Q--)puts("0"); return 0; } if(D.size()>1){ int ans=1; vector F(H,1); for(int i=0;i>r>>c;r--,c--; if(c!=E[0])puts("0"); else cout<1){ int ans=1; vector F(W,1); for(int i=0;i>r>>c;r--,c--; if(r!=D[0])puts("0"); else cout< F(H,1),G(W,1); for(int i=0;i>r>>c;r--,c--; if(c!=E[0] && r!=D[0])puts("0"); else if(c==E[0] && r==D[0])cout<>r>>c;r--,c--; cout<