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 *x*_{i}, *y*_{i} and *d*_{i}.
There is a blank line before each test case.
1 ≤ *N*, *M* ≤ 10000
0 ≤ *R* ≤ 50,000
0 ≤ *x*_{i} < *N*
0 ≤ *y*_{i} < *M*
0 < *d*_{i} < 10000

提交代码