#include using namespace std; using ll=long long; using vin=vector; using vll=vector; using vvin=vector>; using vvll=vector>; using vstr=vector; using vvstr=vector>; using vch=vector; using vvch=vector>; using vbo=vector; using vvbo=vector>; using vpii=vector>; using pqsin=priority_queue,greater>; #define mp make_pair #define rep(i,n) for(int i=0;i<(int)(n);i++) #define rep2(i,s,n) for(int i=(s);i<(int)(n);i++) #define all(v) v.begin(),v.end() #define decp(n) cout<>h>>w; vvll a(h,vll(w)); vll row(h,(ll)1),column(w,(ll)1); ll ap=(ll)1;ll tmp; rep(i,h)rep(j,w){ cin>>a[i][j]; ap*=a[i][j];ap%=inf; tmp=mondiv(a[i][j]); row[i]*=tmp;row[i]%=inf; column[j]*=tmp;column[j]%=inf; } int q;cin>>q; vll ans;int r,c; rep(i,q){ cin>>r>>c;r--;c--; tmp=ap*row[r];tmp%=inf; tmp*=column[c];tmp%=inf; tmp*=a[r][c];tmp%=inf; ans.push_back(tmp); } rep(i,ans.size())cout<