#include #include #include #include #include #include #include #include #include using namespace std; #define rep(i,a,n) for (int i=a;i=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector VI; typedef long long ll; typedef pair PII; const ll mod=1000000007; ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} // head typedef int matrix[60][60]; matrix base,ret,c,tmp; int _,n,m,u,v,k,d[60]; void mul(matrix a,matrix b) { rep(i,0,n) rep(j,0,n) { tmp[i][j]=0; rep(k,0,n) tmp[i][j]=(tmp[i][j]+(ll)a[i][k]*b[k][j])%mod; } rep(i,0,n) rep(j,0,n) a[i][j]=tmp[i][j]; } void powmod(ll b) { rep(i,0,n) rep(j,0,n) c[i][j]=base[i][j],ret[i][j]=(i==j); for (;b;b>>=1) { if(b&1) mul(ret,c);mul(c,c);} } int main() { scanf("%d%d",&n,&m); rep(i,0,m) { scanf("%d%d",&u,&v); --u; --v; d[u]++; base[u][v]++; } rep(i,0,n) { ll v=powmod(d[i],mod-2); rep(j,0,n) base[i][j]=base[i][j]*v%mod; } for (scanf("%d",&_);_;_--) { scanf("%d%d",&u,&k); --u; powmod(k); rep(j,0,n) { printf("%d ",ret[u][j]); } puts(""); } }