structmat { int arr[150][150]; mat() { for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) arr[i][j] = 0; } mat operator*(mat &b) { mat c; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) for(int k = 0; k < n; k++) c.arr[i][j] = (c.arr[i][j] + 1LL * arr[i][k] * b.arr[k][j]) % MOD; return c; } };
signedmain(){ EmiliaMyWife int m, q, l; cin >> n >> m >> q >> l; mat res, owo; for(int i = 0; i < n; i++) res.arr[i][i] = 1; //初始化為單位矩陣 for(int i = 0, a, b; i < m; i++) { cin >> a >> b; owo.arr[a][b]++; } //鄰接矩陣 for(; l; owo = owo * owo, l >>= 1) if(l & 1) res = res * owo; //矩陣快速冪
while(q--) { int a, b; cin >> a >> b; cout << res.arr[a][b] << '\n'; } }