P18775 [HackerEarth] Now Mr. MAZ is running short on sleeping pills, so he is searching them from planets to planets.
普及
题目描述

Now Mr. MAZ is running short on sleeping pills, so he is searching them from planets to planets.
Finally he reaches the planet where he finds them.
There are many countries and in each country there may be one or more cities and a country can be a part of another country. Each city has 0 (zero) or more sleeping pills. Cities are connected by unidirectional paths.
A country is defined as a group of well connected cities such that if we start from any city of that country we can come back to that same city following the unidirectional paths.
Mr. MAZ is allowed to visit only one country. You being his favorite student, he asked you to help him select the country that has maximum number of pills.

Input:
First line of test file contains T, denoting number of test cases.
Next line of each test case contain two space separated integers N and M. N - number of cities and M - number of paths.
Next line contain N space separated integers denoting the number of pills in i^th city.
Next M lines each contains two space separated integers A and B denoting path from A to B.

Output:
For each test case output single integer containing maximum number of pills that he can collect by visiting only one country.

Constraints:
1 ≤ T ≤ 100
1 ≤ N ≤ 100
0 ≤ Number of pills in cities ≤ 1000
0 ≤ M ≤ N(N-1)
0* ≤ A,B < N

No Partial Marking for this question

Problem Setter: Prashant Arya

SAMPLE INPUT
3
5 5
2 3 5 11 12
0 1
1 2
2 0
2 3
3 4
5 5
2 3 5 1 2
0 1
1 2
2 0
2 3
3 4
5 6
2 3 4 1 3
0 1
1 2
2 0
1 3
3 4
4 2

SAMPLE OUTPUT
12
10
13

输入格式

见题面

输出格式

见题面

样例输入
20 6 6 889 325 402 107 762 934 0 3 3 2 3 1 4 2 4 0 0 0 1 0 448 5 14 528 539 692 229 374 4 3 4 4 3 1 1 3 2 3 2 1 3 0 4 2 0 4 1 1 3 4 2 4 3 3 0 3 9 7 634 438 837 725 480 268 628 4 455 8 0 3 7 7 5 0 3 2 4 3 0 3 6 2 1 835 496 0 0 9 61 84 111 108 751 691 760 879 275 159 1 6 1 7 6 7 7 1 0 6 5 6 8 3 1 4 6 1 2 2 4 3 8 2 5 3 7 5 3 3 5 1 1 2 2 6 8 5 6 8 0 7 4 0 5 5 0 5 3 1 5 2 0 8 3 2 6 3 0 1 7 7 3 0 7 6 1 1 7 3 3 6 3 7 6 4 8 6 7 4 4 2 4 1 7 0 8 4 6 2 4 8 2 3 8 7 5 7 4 5 4 4 6 0 2 1 2 7 8 1 2 8 6 6 5 0 2 0 8 0 2 5 1 0 533 3 5 25 337 998 1 1 2 1 0 0 1 0 0 1 6 11 165 181 439 366 636 333 1 5 3 2 2 1 2 0 3 4 1 3 2 2 5 0 0 4 1 0 4 1 5 3 481 522 298 212 231 2 3 4 1 0 2 7 17 999 741 976 618 318 54 983 3 5 3 4 3 3 0 5 3 0 0 3 1 3 5 6 2 3 3 6 6 1 6 0 2 5 6 3 4 4 0 4 2 2 2 0 641 498 3 0 296 905 849 3 1 914 324 286 0 1 8 1 13 609 694 28 448 512 198 172 5 7 9 63 593 277 802 626 355 225 229 373 322 1 6 1 1 6 1 4 6 6 4 5 5 1 5 0 5 8 0 7 2 1 4 8 8 8 2 4 8 5 1 3 4 3 0 6 2 8 1 4 7 3 7 8 5 0 6 7 5 5 0 5 3 5 7 5 2 6 3 0 3 7 6 3 3 8 6 6 7 2 8 7 8 3 8 6 8 6 6 4 5 7 0 0 8 0 0 0 4 2 7 7 4 2 6 7 7 4 4 4 0 0 7 2 4 3 1 1 7 6 0 3 6 0 2 7 3 1 8 7 1 5 8 4 2 1 2 1 0 217 3 1 489 991 598 2 2 3 1 123 794 585 1 2 4 0 922 942 692 58
样例输出
25068 24296 47856 43448 18173 41120 14333 46383 22778 6961 43631 30653 36725 38640 18832 34980 968 41721 19154 29833