DGL's city has a total of m subway lines, numbered as Line 1, Line 2, ..., Line m. The entire city has n stations, numbered from 1 to n. The cost of taking Line i is ai, and the cost increases by bi for each additional station. Line i has ci stations, and these ci stations are known. If multiple subway lines pass through the same station, you can transfer to another line at that station, and you can transfer multiple times. Now, DGL wants to take the subway from station s to station t. The waiting time for the subway is negligible. Find the minimum cost, or output -1 if it's not possible to reach the destination.
Note that the subway is bidirectional, so you can travel in either direction along the line.
The first line contains a number T (1 ≤ T ≤ 5
), indicating the number of testcases.
For each test case:
Output a single number representing the minimum cost. If it's not possible to reach the destination, output -1.
For the first testcase, Taking Line 1 costs 2 units. Moving from Station 1 to Station 3 costs 2 units. Transferring to Line 2 costs 2 units. Moving from Station 3 to Station 4 costs 1 unit. Therefore, the minimum total cost is 7 units.
For the second testcase, there is no line can go to Station 3.
m = 1
n, m ≤ 100