// karanaggarwal
#include<bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)
#define TR(v,it) for( LET(it,v.begin()) ; it != v.end() ; it++)
#define repi(i,n) for(int i=0; i<(int)n;i++)
#define si(n) scanf("%d",&n)
#define sll(n) scanf("%lld",&n)
#define sortv(a) sort(a.begin(),a.end())
#define all(a) a.begin(),a.end()
#define DRT() int t; cin>>t; while(t--)
#define TRACE
using namespace std;
//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
#ifdef TRACE
#define trace1(x) cerr << #x << ": " << x << endl;
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z) cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;
#else
#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)
#endif
typedef long long LL;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector< PII > VPII;
#define mod 1000000007
LL A[31][31];
LL ret[31][31];
LL og[31][31];
int N;
void mul(LL A[][31], LL B[][31])
{
LL C[31][31];
repi(i,N)
repi(j,N)
{
C[i][j] = 0;
repi(k,N)
C[i][j] += (A[i][k]*B[k][j]) % mod;
}
repi(i,N)
repi(j,N)
A[i][j] = C[i][j]%mod;
}
void power(LL A[][31], LL P)
{
SET(ret,0); for(int i=0; i<N;i++)ret[i][i] = 1;
while(P)
{
if(P&1)
mul(ret,A);
mul(A,A); P/=2;
}
}
LL ans[30][31][31];
int main()
{
int M;
cin>>N>>M;
LL K;
cin>>K; int x,y;
K++;
while(M--)
{
si(x); si(y); x--; y--; A[x][y]++;
}
N++;
repi(i,N)repi(j,N)og[i][j] = A[i][j];
for(int dest = 0; dest<N-1; dest++)
{
repi(i,N)repi(j,N)A[i][j] = og[i][j];
int y = dest;
A[y][N-1] = 1; A[N-1][N-1] = 1;
power(A,K);
repi(i,N)repi(j,N)ans[dest][i][j] = ret[i][j];
ans[y][y][N-1]--; if(ans[y][y][N-1]<0)ans[y][y][N-1]++;
}
int q; si(q); while(q--)
{
int x,y; si(x); si(y); x--; y--;
printf("%lld\n", ans[y][x][N-1]);
}
return 0;
}
Ly8ga2FyYW5hZ2dhcndhbAojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgojZGVmaW5lIFBCIHB1c2hfYmFjawojZGVmaW5lIE1QIG1ha2VfcGFpcgojZGVmaW5lIEYgZmlyc3QKI2RlZmluZSBTIHNlY29uZAojZGVmaW5lIFNaKGEpIChpbnQpKGEuc2l6ZSgpKQojZGVmaW5lIFNFVChhLGIpIG1lbXNldChhLGIsc2l6ZW9mKGEpKQojZGVmaW5lIExFVCh4LGEpIF9fdHlwZW9mKGEpIHgoYSkKI2RlZmluZSBUUih2LGl0KSBmb3IoIExFVChpdCx2LmJlZ2luKCkpIDsgaXQgIT0gdi5lbmQoKSA7IGl0KyspCiNkZWZpbmUgcmVwaShpLG4pIGZvcihpbnQgaT0wOyBpPChpbnQpbjtpKyspCiNkZWZpbmUgc2kobikgc2NhbmYoIiVkIiwmbikKI2RlZmluZSBzbGwobikgc2NhbmYoIiVsbGQiLCZuKQojZGVmaW5lIHNvcnR2KGEpIHNvcnQoYS5iZWdpbigpLGEuZW5kKCkpCiNkZWZpbmUgYWxsKGEpIGEuYmVnaW4oK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