#P7507. [2017年杭电多校]Give out candies

[2017年杭电多校]Give out candies

Give out candies

Problem Description

There are nn children numbered 11 to nn, and HazelFan's task is to give out candies to the children. Each children must be given at least 11 and at most mm candies. The children raised kk pieces of requirements, and every piece includes three integers x,y,zx,y,z, means that the number of candies given to the child numbered xx, subtract the number of candies given to the child number yy, the result should not be more than zz. Besides, if the child numbered ii is given jj candies, he or she will get wi,jw_{i,j} satisfaction score, now you need to help HazelFan maximize the sum of the satisfaction scores of these children.

Input

The first line contains a positive integer T(1T5)T(1\leq T\leq5), denoting the number of test cases. For each test case: The first line contain three positive integers n,m,k(1n,m50,1k150)n,m,k(1\leq n,m\leq50,1\leq k\leq150). The next nn lines, the iith line contains mm positive integers, the jjth integer denotes wi,jw_{i,j}. The next kk lines, each line contains three integers x,y,z(1x,yn,z<233)x,y,z(1\leq x,y\leq n,\mid z\mid<233), denoting a piece of requirement.

Output

For each test case: A single line contains a nonnegative integer, denoting the answer. Particularly, if there is no way to give out candies, print -1.

Sample Input

2

2 1 1

1

1

1 2 1

3 3 2

1 2 3

2 3 1

3 1 2

1 2 0

2 3 0

Sample Output

2

7

Source

2017 Multi-University Training Contest - Team 7

https://acm.hdu.edu.cn/showproblem.php?pid=6126