#include #include using namespace std; const int MOD = 1000000007; long pow(long a, long n, long p) { long res = 1; while(n!=0) { if (n%2) { res *= a; res %= MOD; } a *= a; a %= p; n >>= 1; } return res; } int main() { int h,w; cin >> h >> w; vector> a(h, vector(w,0)); long cpro = 1; for (int i=0; i> a[i][j]; cpro *= a[i][j]; cpro %= MOD; } } vector hpro(h,1); for (int i=0; i wpro(h,1); for (int i=0; i> q; for (int i=0; i> r >> c; long ans = cpro; (ans *= pow(hpro[r-1], MOD-2, MOD)) %= MOD; (ans *= pow(wpro[c-1], MOD-2, MOD)) %= MOD; (ans *= a[r-1][c-1]) %= MOD; cout << ans << endl; } }