Nadaca is a country with N$N$ cities. These cities are numbered 1$1$ through N$N$ and connected by M$M$ bidirectional roads. Each city can be reached from every other city using these roads.
Initially, Ryan is in city 1$1$. At each of the following K$K$ seconds, he may move from his current city to an adjacent city (a city connected by a road to his current city) or stay at his current city. Ryan also has Q$Q$ conditions (a1,b1),(a2,b2),…,(aQ,bQ)$(a_1, b_1), (a_2, b_2), \ldots, (a_Q, b_Q)$ meaning that during this K$K$-second trip, for each valid i$i$, he wants to be in city ai$a_i$ after exactly bi$b_i$ seconds.
Since you are very good with directions, Ryan asked you to tell him how many different trips he could make while satisfying all conditions. Compute this number modulo 109+7$10^9 + 7$. A trip is a sequence of Ryan's current cities after 1,2,…,K$1, 2, \ldots, K$ seconds.

-----Input-----
- The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows.
- The first line of each test case contains three space-separated integers N$N$, M$M$ and K$K$.
- Each of the next M$M$ lines contains two space-separated integers u$u$ and v$v$ denoting a road between cities u$u$ and v$v$.
- The next line contains a single integer Q$Q$.
- Q$Q$ lines follow. For each i$i$ (1≤i≤Q$1 \le i \le Q$), the i$i$-th of these lines contains two space-separated integers ai$a_i$ and bi$b_i$.

-----Output-----
For each test case, print a single line containing one integer — the number of trips Ryan can make, modulo 109+7$10^9+7$.

-----Constraints-----
- 1≤T≤50$1 \le T \le 50$
- 1≤N,M,K,Q≤9,000$1 \le N, M, K, Q \le 9,000$
- 1≤ui,vi≤N$1 \le u_i, v_i \le N$ for each valid i$i$
- ui≠vi$u_i \neq v_i$ for each valid i$i$
- there is at most one road between each pair of cities
- each city is reachable from every other city
- 1≤ai≤N$1 \le a_i \le N$ for each valid i$i$
- 0≤bi≤K$0 \le b_i \le K$ for each valid i$i$
- the sum of N$N$ over all test cases does not exceed 9,000$9,000$
- the sum of K$K$ over all test cases does not exceed 9,000$9,000$
- the sum of M$M$ over all test cases does not exceed 9,000$9,000$
- the sum of Q$Q$ over all test cases does not exceed 9,000$9,000$

-----Subtasks-----
Subtask #1 (20 points):
- the sum of N$N$ over all test cases does not exceed 400$400$
- the sum of K$K$ over all test cases does not exceed 400$400$
- the sum of M$M$ over all test cases does not exceed 400$400$
- the sum of Q$Q$ over all test cases does not exceed 400$400$
Subtask #2 (80 points): original constraints

-----Example Input-----
3
4 3 3
1 2
1 3
1 4
0
4 3 3
1 2
1 3
1 4
1
2 2
4 3 3
1 2
1 3
1 4
1
2 1

-----Example Output-----
28
4
6

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'T = int(input())\nfor _ in range(T):\n    N, M, K = [int(x) for x in input().split()]\n    UV = [[int(x) for x in input().split()] for _ in range(M)]\n    Q = int(input())\n    AB = [[int(x) for x in input().split()] for _ in range(Q)]\n \n    X = [[i] for i in range(N)]\n    for u, v in UV:\n     X[u - 1] += [v - 1]\n     X[v - 1] += [u - 1]\n \n    A = [[1 if i > 0 or j == 0 else 0 for j in range(N)] for i in range(K + 1)]\n    for a, b in AB:\n     A[b] = [1 if i == a - 1 else 0 for i in range(N)]\n \n    if A[0][0] == 1:\n     for k in range(K - 1, -1, -1):\n      for i in range(N):\n       if A[k][i] != 0:\n        A[k][i] = sum(A[k + 1][j] for j in X[i])\n \n    print(A[0][0])'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13533