"Life is too short to make a story", said Ahmed Aly, so this problem gets straight to the point.
You are given a weighted directed graph with N nodes numbered from 1 to N. Every edge weight is a positive integer, and all edge weights are distinct.
A query is three integers A, B, C. Consider the paths that start at node A, end at node B, use at most C edges, and whose edge weights grow along the path: every edge must weigh more than the edge taken just before it. The first edge of a path carries no such restriction.
For each query, find the smallest possible sum of edge weights over those paths.
The first line contains one integer T, the number of test cases (1≤T≤100).
Each test case begins with a line holding three integers separated by a single space, N, M and Q (2≤N≤150, 0≤M≤3000, 1≤Q≤1000): the number of nodes, edges and queries.
The next M lines each contain three integers separated by a single space, X, Y and Z (1≤X,Y≤N, 1≤Z≤3000, X=Y), an edge going from node X to node Y with weight Z. There might be multiple edges between the same pair of nodes.
The next Q lines each contain three integers separated by a single space, A, B and C (1≤A,B≤N, 0≤C≤M, A=B), one query as described above.
For each query, print one line with the minimum sum of edge weights of a path that satisfies the constraints, or −1 if no such path exists. Do not print blank lines between test cases.