Problem: There are cities located on the number line, the -th city is in the point . The coordinates of the cities are given in ascending order, so .
The distance between two cities and is equal to .
For each city , let's define the closest city as the city such that the distance between and is not greater than the distance between and each other city . For example, if the cities are located in points , then:
- the closest city to the city is the city ;
- the closest city to the city is the city ;
- the closest city to the city is the city ;
- the closest city to the city is the city ;
- the closest city to the city is the city .
The cities are located in such a way that for every city, the closest city is unique. For example, it is impossible for the cities to be situated in points , since this would mean that the city has two closest cities ( and , both having distance ).
You can travel between cities. Suppose you are currently in the city . Then you can perform one of the following actions:
- travel to any other city , paying coins;
- travel to the city which is the closest to , paying coin.
You are given queries. In each query, you will be given two cities, and you have to calculate the minimum number of coins you have to spend to travel from one city to the other city.
Input Format: The first line contains one integer () — the number of test cases.
Each test case is given in the following format:
- the first line contains one integer ();
- the second line contains integers ();
- the third line contains one integer ();
- then lines follow; the -th of them contains two integers and (; ), denoting that in the -th query, you have to calculate the minimum number of coins you have to spend to travel from the city to the city .
Additional constraints on the input:
- in every test case, for each city, the closest city is determined uniquely;
- the sum of over all test cases does not exceed ;
- the sum of over all test cases does not exceed .
Output Format: For each query, print one integer — the minimum number of coins you have to spend.
Note: Let's consider the first two queries in the example from the statement:
- in the first query, you are initially in the city . You can travel to the closest city (which is the city ), paying coin. Then you travel to the closest city (which is the city ) again, paying coin. Then you travel to the closest city (which is the city ) again, paying coin. In total, you spend coins to get from the city to the city ;
- in the second query, you can use the same way to get from the city to the city , and then spend coins to travel from the city to the city .