#include // cout, endl, cin #include // string, to_string, stoi #include // vector #include // min, max, swap, sort, reverse, lower_bound, upper_bound #include // pair, make_pair #include // tuple, make_tuple #include // int64_t, int*_t #include // printf #include // map #include // queue, priority_queue #include // set #include // stack #include // deque #include // unordered_map #include // unordered_set #include // bitset #include // isupper, islower, isdigit, toupper, tolower #include // setprecision #include // complex #include #define enld '\n' using namespace std; using ll = long long; using P = pair; constexpr ll INF = 1e18; constexpr int inf = 1e9; constexpr ll mod = 1000000007; constexpr ll mod2 = 998244353; const int dx[8] = {1, 0, -1, 0,1,1,-1,-1}; const int dy[8] = {0, 1, 0, -1,1,-1,1,-1}; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } // --------------------------------------------------------------------------- struct mint { ll x; // typedef long long ll; mint(ll x=0):x((x%mod+mod)%mod){} mint& operator+=(const mint a) { if ((x += a.x) >= mod) x -= mod; return *this; } mint& operator-=(const mint a) { if ((x += mod-a.x) >= mod) x -= mod; return *this; } mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; } mint operator+(const mint a) const { mint res(*this); return res+=a; } mint operator-(const mint a) const { mint res(*this); return res-=a; } mint operator*(const mint a) const { mint res(*this); return res*=a; } mint pow(ll t) const { if (!t) return 1; mint a = pow(t>>1); a *= a; if (t&1) a *= *this; return a; } // for prime mod mint inv() const { return pow(mod-2); } mint& operator/=(const mint a) { return (*this) *= a.inv(); } mint operator/(const mint a) const { mint res(*this); return res/=a; } }; // mint N; //cout << N.x << endl; int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int H,W; cin >> H >> W; vector> G(H,vector(W,1)); vector cnt_H(H,0); vector cnt_W(W,0); mint all = 1; set

se; for(int i=0; i> a; if(a){ G[i][j] = a; all *= a; }else{ se.emplace(i,j); cnt_H[i]++; cnt_W[j]++; } } } vector sum_H(H,1); for(int i=0; i sum_W(W,1); for(int i=0; i> Q; for(int i=0; i> r >> c; r--;c--; int sum = se.size(); if(se.count(P(r,c))) sum--; if(cnt_H[r] + cnt_W[c] != sum){ cout << 0 << "\n"; continue; } if(se.count(P(r,c))){ cout << (all/sum_H[r]/sum_W[c]).x << "\n"; }else{ cout << (all/sum_H[r]/sum_W[c]*G[r][c]).x << "\n"; } } return 0; }