#436. New Equipments II
New Equipments II
Description
Little Q's factory recently purchased pieces of new equipment, labeled by .
There are workers in the factory, labeled by . Each worker can be assigned to no more than one piece of equipment, and no piece of equipment can be assigned to multiple workers. If Little Q assigns the -th worker to the -th piece of equipment, they will bring profits. However, these workers are not so experienced, there are extra constraints. In each constraint, you will be given two integers and , denoting the -th worker can't be assigned to the -th piece of equipment.
Now please for every () find pairs of workers and pieces of equipment, then assign workers to these pieces of equipment, such that the total profits for these pairs are maximized, or determine it is impossible.
Format
Input
The first line contains a single integer (), the number of test cases. For each test case:
The first line contains two integers and (, ), denoting the number of workers/pieces of new equipment and the number of constraints.
The second line contains integers ().
The third line contains integers ().
Each of the following lines contains two integers and (), denoting the -th worker can't be assigned to the -th piece of equipment. Each pair of and will be described at most once.
It is guaranteed that there will be at most test cases such that .
Output
For each test case, output lines, the -th () of which containing an integer, denoting the maximum possible total profits for pairs of workers and pieces of equipment. Note that if it is impossible to find such pairs, print '''' at this line.
Samples
2
4 4
10 20 30 40
5 10 7 8
4 2
3 2
1 4
1 2
2 2
1 1
1 1
1 1
1 2
48
85
115
130
2
-1