#P1704E. Count Seconds

    ID: 950 Type: RemoteJudge 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 8 Uploaded By: Tags>brute forceconstructive algorithmsdpgraphsimplementationmath*2200

Count Seconds

Description

Cirno has a DAG (Directed Acyclic Graph) with nn nodes and mm edges. The graph has exactly one node that has no out edges. The ii-th node has an integer aia_i on it.

Every second the following happens:

  • Let SS be the set of nodes xx that have ax>0a_x > 0.
  • For all xSx \in S, 11 is subtracted from axa_x, and then for each node yy, such that there is an edge from xx to yy, 11 is added to aya_y.

Find the first moment of time when all aia_i become 00. Since the answer can be very large, output it modulo 998244353998\,244\,353.

The first line contains a single integer tt (1t10001 \leq t \leq 1000) — the number of test cases. Description of test cases follows.

The first line of each test case contains two integers n,mn, m (1n,m10001 \leq n, m \leq 1000) — the number of vertices and edges in the graph.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai1090 \leq a_i \leq 10^9) — the integer on vertices.

Each line of the following mm lines contains two integers x,yx, y (1x,yn1 \leq x, y \leq n), represent a directed edge from xx to yy. It is guaranteed that the graph is a DAG with no multi-edges, and there is exactly one node that has no out edges.

It is guaranteed that both sum of nn and sum of mm over all test cases are less than or equal to 1000010\,000.

For each test case, print an integer in a separate line — the first moment of time when all aia_i become 00, modulo 998244353998\,244\,353.

Input

The first line contains a single integer tt (1t10001 \leq t \leq 1000) — the number of test cases. Description of test cases follows.

The first line of each test case contains two integers n,mn, m (1n,m10001 \leq n, m \leq 1000) — the number of vertices and edges in the graph.

The second line of each test case contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (0ai1090 \leq a_i \leq 10^9) — the integer on vertices.

Each line of the following mm lines contains two integers x,yx, y (1x,yn1 \leq x, y \leq n), represent a directed edge from xx to yy. It is guaranteed that the graph is a DAG with no multi-edges, and there is exactly one node that has no out edges.

It is guaranteed that both sum of nn and sum of mm over all test cases are less than or equal to 1000010\,000.

Output

For each test case, print an integer in a separate line — the first moment of time when all aia_i become 00, modulo 998244353998\,244\,353.

Sample Input 1

5
3 2
1 1 1
1 2
2 3
5 5
1 0 0 0 0
1 2
2 3
3 4
4 5
1 5
10 11
998244353 0 0 0 998244353 0 0 0 0 0
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
1 3
7 9
5 6
1293 1145 9961 9961 1919
1 2
2 3
3 4
5 4
1 4
2 4
6 9
10 10 10 10 10 10
1 2
1 3
2 3
4 3
6 3
3 5
6 5
6 1
6 2

Sample Output 1

3
5
4
28010
110

Note

In the first test case:

  • At time 00, the values of the nodes are [1,1,1][1, 1, 1].
  • At time 11, the values of the nodes are [0,1,1][0, 1, 1].
  • At time 22, the values of the nodes are [0,0,1][0, 0, 1].
  • At time 33, the values of the nodes are [0,0,0][0, 0, 0].

So the answer is 33.

    In the second test case:
  • At time 00, the values of the nodes are [1,0,0,0,0][1, 0, 0, 0, 0].
  • At time 11, the values of the nodes are [0,1,0,0,1][0, 1, 0, 0, 1].
  • At time 22, the values of the nodes are [0,0,1,0,0][0, 0, 1, 0, 0].
  • At time 33, the values of the nodes are [0,0,0,1,0][0, 0, 0, 1, 0].
  • At time 44, the values of the nodes are [0,0,0,0,1][0, 0, 0, 0, 1].
  • At time 55, the values of the nodes are [0,0,0,0,0][0, 0, 0, 0, 0].
So the answer is 55.

In the third test case:

The first moment of time when all aia_i become 00 is 6998244353+46\cdot 998244353 + 4.