You are the King of Byteland, which now consists of K rival states. The national day of Byteland is approaching, and it is a day of great merriment. Each of the K states is throwing its own party. Fortunately your kingdom also has N rich and famous entertainers, numbered from 0 to N-1. Its your job to allocate to each state, some non empty set of entertainers. Note that the same entertainer cannot be allocated to two different states. Some entertainers may be unallocated. Also to each allocated entertainer, you must pay C coins to hire him.
The trouble is, some of the entertainers are fond of some others, and refuse to spend the national day without their friends, meaning they insist on being allocated to the same state if they are allocated). Under this constraint, you find out that allocating entertainers to the states becomes impossible. So you appeal to them to relax their requirements, and they ask you to donate more money to the entertainment industry. More formally, you will be provided with a 2-dimensional array R. If the total amount of money you donate is less than R[u][v], for u not equal to v, then entertainer #u will NOT agree to spend the national day without the company of entertainer #v. Note that if you do not allocate entertainer #u, then you can safely ignore his restrictions. R[u][v] need not be equal to R[v][u].
You are free to donate any non-negative amount of coins as you see fit. Find out the minimum expenditure you must make to satisfy all entertainers and all states. Note that your total expenditure is : (the amount of money you donate + C * the number of allocated entertainers).
The first line contains T, the number of test cases. Each test contains 3 lines.
In case 1, we get R[1][0] = 20 and R[0][1] = 8. The optimal choice is to donate 8 coins, and allocate entertainer #0 to the only state.
In case 2, R[1][0] = 20 and R[0][1] = 12. The optimal choice here is to donate 0 coins, and allocate both entertainers to the only state.