Walking Plan

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

There are nn intersections in Bytetown, connected with mm one-way streets. These intersections are labeled by 1,2,,n1,2,\dots,n. Little Q likes sport walking very much, he plans to walk for qq days. On the ii-th day, Little Q plans to start walking at the s_is\_i-th intersection, move along a street at least k_ik\_i times, and finally arrive to the t_it\_i-th intersection. Note that k_ik\_i is the required number of moves, not streets: it is allowed to use any street more than once.

Little Q's smartphone will record his walking route. Little Q cares more about statistics than about staying healthy. So he wants to minimize the total walking length on each day. Please write a program to help him find the best route.

입력

The first line contains a single integer TT (1T101 \leq T \leq 10), the number of test cases. For each test case:

The first line contains two integers nn and mm (2n502 \leq n \leq 50, 1m10,0001 \leq m \leq 10\\,000) denoting the number of intersections and one-way streets.

Each of the next mm lines contains three integers u_iu\_i, v_iv\_i, w_iw\_i (1u_i,v_in1 \leq u\_i, v\_i \leq n, u_iv_iu\_i \neq v\_i, 1w_i10,0001 \leq w\_i \leq 10\\,000) denoting a one-way street from intersection u_iu\_i to intersection v_iv\_i with length w_iw\_i.

In the next line, there is an integer qq (1q100,0001 \leq q \leq 100\\,000) denoting the number of days.

Each of the next qq lines contains three integers s_is\_i, t_it\_i, k_ik\_i (1s_i,t_in1 \leq s\_i, t\_i \leq n, 1k_i10,0001 \leq k\_i \leq 10\\,000) describing the walking plan.

출력

For each walking plan, print a line containing a single integer: the minimum total walking length. If there is no solution, please print "-1".