There are n intersections in Bytetown, connected with m one-way streets. These intersections are labeled by 1,2,…,n. Little Q likes sport walking very much, he plans to walk for q days. On the i-th day, Little Q plans to start walking at the s_i-th intersection, move along a street at least k_i times, and finally arrive to the t_i-th intersection. Note that k_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 T (1≤T≤10), the number of test cases. For each test case:
The first line contains two integers n and m (2≤n≤50, 1≤m≤10,000) denoting the number of intersections and one-way streets.
Each of the next m lines contains three integers u_i, v_i, w_i (1≤u_i,v_i≤n, u_i=v_i, 1≤w_i≤10,000) denoting a one-way street from intersection u_i to intersection v_i with length w_i.
In the next line, there is an integer q (1≤q≤100,000) denoting the number of days.
Each of the next q lines contains three integers s_i, t_i, k_i (1≤s_i,t_i≤n, 1≤k_i≤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".