Instant Noodles
문제
Wu got hungry after an intense training session, and came to a nearby store to buy his favourite instant noodles. After Wu paid for his purchase, the cashier gave him an interesting task.
You are given a bipartite graph with positive integers in all vertices of the right half. For a subset of vertices of the left half we define as the set of all vertices of the right half adjacent to at least one vertex in , and as the sum of all numbers in vertices of . Find the greatest common divisor of for all possible non-empty subsets .
Wu is too tired after his training to solve this problem. Help him!
입력
The first line contains a single integer () --- the number of test cases in the given test set. Test case descriptions follow.
The first line of each case description contains two integers and () --- the number of vertices in either half of the graph, and the number of edges respectively.
The second line contains integers (). The -th number describes the integer in the vertex of the right half of the graph.
Each of the following lines contains a pair of integers and (), describing an edge between the vertex of the left half and the vertex of the right half. It is guaranteed that the graph does not contain multiple edges.
Test case descriptions are separated with empty lines. The total value of across all test cases does not exceed , and the total value of across all test cases does not exceed as well.
출력
For each test case print a single integer --- the required greatest common divisor.
힌트
The greatest common divisor of a set of integers is the largest integer such that all elements of the set are divisible by .
In the first sample case vertices of the left half and vertices of the right half are pairwise connected, and for any non-empty subset is , thus the greatest common divisor of these values if also equal to .
In the second sample case the subset in the left half is connected to vertices of the right half, with the sum of numbers equal to , and the subset in the left half is connected to vertices of the right half, with the sum of numbers equal to . Thus, , , which means that the greatest common divisor of all values of is .
예제
예제 1
3 2 4 1 1 1 1 1 2 2 1 2 2 3 4 1 1 1 1 1 1 2 2 2 2 3 4 7 36 31 96 29 1 2 1 3 1 4 2 2 2 4 3 1 4 3
2 1 12