Increasing Shortest Path

No attempts yetTime limit15sMemory limit256 MB

Problem

"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 NN nodes numbered from 11 to NN. Every edge weight is a positive integer, and all edge weights are distinct.

A query is three integers AA, BB, CC. Consider the paths that start at node AA, end at node BB, use at most CC 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.

Input

The first line contains one integer TT, the number of test cases (1T1001 \le T \le 100).

Each test case begins with a line holding three integers separated by a single space, NN, MM and QQ (2N1502 \le N \le 150, 0M30000 \le M \le 3000, 1Q10001 \le Q \le 1000): the number of nodes, edges and queries.

The next MM lines each contain three integers separated by a single space, XX, YY and ZZ (1X,YN1 \le X, Y \le N, 1Z30001 \le Z \le 3000, XYX \ne Y), an edge going from node XX to node YY with weight ZZ. There might be multiple edges between the same pair of nodes.

The next QQ lines each contain three integers separated by a single space, AA, BB and CC (1A,BN1 \le A, B \le N, 0CM0 \le C \le M, ABA \ne B), one query as described above.

Output

For each query, print one line with the minimum sum of edge weights of a path that satisfies the constraints, or 1-1 if no such path exists. Do not print blank lines between test cases.