## Description

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.

## Input

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

## Output

For each test case output the answer in a single line.

## Sample Input

1 | 2 |

## Sample Output

1 | 71071 |

## Answer

1 | `#include <cstdio>` |

## Analysis

- 花费费用最少，则选取全部顶点花费的代价最大。即最大生成树？将边权重全部取反，即是最小生成树。
- kruskal 求最小生成树。
- https://blog.csdn.net/u013480600/article/details/37996747