Problem
Tom is taking metros in the city to go from station to station.
The metro system in the city works like this:
- There are N metro lines in the city: line 1, line 2, ..., line N.
- For each metro i, there are SNi stations. Let's assume they are Si,1,Si,2, ... , Si,SNi. These stations are ordered from one end point to the other end point. The metro is running in both directions. In other words, the metro is going from Si,1 -> Si,2 -> ... -> Si,SNi, and Si,SNi -> Si,SNi-1 -> ... -> Si,1. You can take the metro from any station and get off at any station. It takes a certain time to travel from one station to the next station. It takes Timei,1 minutes to travel from Si,1 to Si,2, Timei,2 minutes to travel from Si,2 to Si,3, etc. It takes the same time in the other direction.
- There are M transfer tunnels. Each transfer tunnel connects two stations of different metro lines. It takes a certain amount of time to travel through a tunnel in either direction. You can get off the metro at one end of the tunnel and walk through the tunnel to the station at the another end.
- When you arrive at a metro station of line i, you need to wait Wi minutes for the next metro.
Now, you are going to travel from one station to another. Find out the shortest time you need.
Input
The first line of the input gives the number of test cases, T. T test cases follow.
Each test case starts with an integer N, the number of metro lines. N metros descriptions follow. Each metro description starts with two integers SNi and Wi, the number of stations and th