Windy has a country, and he wants to build an army to protect his country. He has picked up N girls and M boys and wants to collect them to be his soldiers. To collect a soldier without any privilege, he must pay 10000 RMB. There are some relationships between girls and boys and Windy can use these relationships to reduce his cost. If girl x and boy y have a relationship d and one of them has been collected, Windy can collect the other one with 10000-d RMB. Now given all the relationships between girls and boys, your assignment is to find the least amount of money Windy has to pay. Notice that only one relationship can be used when collecting one soldier.
The first line of input is the number of test case. The first line of each test case contains three integers, N, M and R. Then R lines followed, each contains three integers xi, yi and di. There is a blank line before each test case.
1 ≤ N, M ≤ 10000 0 ≤ R ≤ 50,000 0 ≤ xi < N 0 ≤ yi < M 0 < di < 10000
For each test case output the answer in a single line.
- kruskal 求最小生成树。