1 //{HEADS
2 #define FILE_IN_OUT
3 #define debug
4 #include <cstdio>
5 #include <cstring>
6 #include <cstdlib>
7 #include <cmath>
8 #include <ctime>
9 #include <algorithm>
10 #include <iostream>
11 #include <fstream>
12 #include <vector>
13 #include <stack>
14 #include <queue>
15 #include <deque>
16 #include <map>
17 #include <set>
18 #include <bitset>
19 #include <complex>
20 #include <string>
21 #define REP(i, j) for (int i = 0; i < j; ++i)
22 #define REPI(i, j, k) for (int i = j; i <= k; ++i)
23 #define REPD(i, j) for (int i = j; 0 < i; --i)
24 #define STLR(i, con) for (int i = 0, sz = con.size(); i < sz; ++i)
25 #define STLRD(i, con) for (int i = con.size() - 1; 0 <= i; --i)
26 #define CLR(s) memset(s, 0, sizeof s)
27 #define SET(s, v) memset(s, v, sizeof s)
28 #define pb push_back
29 #define PL(k, n) for (int i = 1; i <= n; ++i) { cout << k[i] << ‘ ‘; } cout << endl
30 #define PS(k) STLR(i, k) { cout << k[i] << ‘ ‘; } cout << endl
31 using namespace std;
32 #ifdef debug
33 #ifndef ONLINE_JUDGE
34 const int OUT_PUT_DEBUG_INFO = 1;
35 #endif
36 #endif
37 #ifdef ONLINE_JUDGE
38 const int OUT_PUT_DEBUG_INFO = 0;
39 #endif
40 #define DG if(OUT_PUT_DEBUG_INFO)
41 void FILE_INIT(string FILE_NAME) {
42 #ifdef FILE_IN_OUT
43 #ifndef ONLINE_JUDGE
44 freopen((FILE_NAME + ".in").c_str(), "r", stdin);
45 freopen((FILE_NAME + ".out").c_str(), "w", stdout);
46
47 #endif
48 #endif
49 }
50 typedef long long LL;
51 typedef double DB;
52 typedef pair<int, int> i_pair;
53 const int INF = 0x3f3f3f3f;
54 //}
55
56 const int mod = 10000;
57 const int maxn = 50 + 1;
58 int n, m, start, end, k, n_fish;
59 struct Matrix {
60 int d[maxn][maxn];
61 Matrix() {
62 memset(d, 0, sizeof d);
63 }
64 }G[12];
65 int mp[maxn][maxn], p[maxn];
66 Matrix operator * (Matrix &a, Matrix &b) {
67 Matrix ret;
68 REP(i, n) {
69 REP(j, n) {
70 REP(k, n) {
71 ret.d[i][j] = (ret.d[i][j] + a.d[i][k] * b.d[k][j]) % mod;
72 }
73 }
74 }
75 return ret;
76 }
77
78 /*{ 快速幂*/
79
80 Matrix fast_pow(Matrix base, int index) {
81 Matrix ret;
82 REP(i, n) {
83 ret.d[i][i] = 1;
84 }
85 for(; index; index >>= 1, base = base * base) {
86 if(index & 1) {
87 ret = ret * base;
88 }
89 }
90 return ret;
91 }
92
93 /*}*/
94
95 int main() {
96 FILE_INIT("BZOJ1898");
97
98 scanf("%d%d%d%d%d", &n, &m, &start, &end, &k);
99 for(int a, b; m; --m) {
100 scanf("%d %d", &a, &b);
101 mp[a][b] = mp[b][a] = 1;
102 }
103 for(int i = 0; i < 12; ++i) {
104 memcpy(G[i].d, mp, sizeof mp);
105 }
106 scanf("%d", &n_fish);
107 REP(i, n_fish) {
108 int t;
109 scanf("%d", &t);
110 for(int j = 0; j < t; ++j) {
111 scanf("%d", &p[j]);
112 }
113 for(int j = 0; j < 12; ++j) {
114 int b = p[j % t];
115 REP(l, n) {
116 if(j) {
117 G[j - 1].d[l][b] = 0;
118 }
119 G[j].d[b][l] = 0;
120 }
121 }
122 }
123 Matrix ans, base;
124 for(int i = 0; i < n; ++i) {
125 base.d[i][i] = 1;
126 }
127 for(int i = 0; i < 12; ++i) {
128 base = base * G[i];
129 }
130 ans = fast_pow(base, k / 12);
131 k %= 12;
132 for(int i = 0; i < k; ++i) {
133 ans = ans * G[i];
134 }
135 printf("%d\n", ans.d[start][end]);
136
137 return 0;
138 }