#include using namespace std; const int64_t MOD = 1e9+7; void add(int64_t& a, int64_t b){ a = (a+b) % MOD; } void mul(int64_t& a, int64_t b){ a = a*b % MOD; } template struct Segtree { int n, n_org; T e; vector dat; typedef function Func; Func f; Segtree(){} Segtree(int n_input, Func f_input, T e_input){ initialize(n_input, f_input, e_input); } void initialize(int n_input, Func f_input, T e_input){ n_org = n_input; f = f_input; e = e_input; n = 1; while(n < n_input) n <<= 1; dat.assign(2*n-1, e); } void build(vector& A){ for(int k=0; k=0; k--) dat[k] = f(dat[2*k+1], dat[2*k+2]); } void update(int k, T a){ k += n - 1; mul(dat[k], a); while(k > 0){ k = (k - 1)/2; dat[k] = f(dat[2*k+1], dat[2*k+2]); } } T get(int k){ return dat[k+n-1]; } T between(int a, int b){ return query(a, b+1, 0, 0, n); } T query(int a, int b, int k, int l, int r){ if(r<=a || b<=l) return e; if(a<=l && r<=b) return dat[k]; T vl = query(a, b, 2*k+1, l, (l+r)/2); T vr = query(a, b, 2*k+2, (l+r)/2, r); return f(vl, vr); } }; template struct Segtree2D { int n, n_org; T e; vector> dat; typedef function Func; Func f; Segtree2D(){} Segtree2D(int n_input, int m_input, Func f_input, T e_input){ initialize(n_input, m_input, f_input, e_input); } void initialize(int n_input, int m_input, Func f_input, T e_input){ n_org = n_input; f = f_input; e = e_input; n = 1; while(n < n_input) n <<= 1; dat.resize(2*n-1); for(int i=0; i<2*n-1; i++) dat[i] = Segtree(m_input, f_input, e_input); } void update(int k, int x, T a){ k += n - 1; dat[k].update(x, a); while(k > 0){ k = (k - 1)/2; dat[k].update(x, a); } } T between(int a, int b, int s, int t){ return query(a, b+1, 0, 0, n, s, t); } T query(int a, int b, int k, int l, int r, int s, int t){ if(r<=a || b<=l) return e; if(a<=l && r<=b) return dat[k].between(s, t); T vl = query(a, b, 2*k+1, l, (l+r)/2, s, t); T vr = query(a, b, 2*k+2, (l+r)/2, r, s, t); return f(vl, vr); } }; int main(){ int H, W; cin >> H >> W; Segtree2D st(H, W, [](auto a, auto b){ return a*b%MOD; }, 1); for(int i=0; i> a; st.update(i, j, a); } int Q; cin >> Q; while(Q--){ int r, c; cin >> r >> c; r--; c--; int64_t ans = 1; mul(ans, st.between(0, r-1, 0, c-1)); mul(ans, st.between(r+1, H-1, 0, c-1)); mul(ans, st.between(0, r-1, c+1, W-1)); mul(ans, st.between(r+1, H-1, c+1, W-1)); cout << ans << endl; } return 0; }