A works as the janitor of an office building. Every night at midnight, A turns off every office light that is still on, turns off the electronic signboard on the building's roof, and then goes home.
The building has an unusual layout. Every floor holds the same number of offices lined up in a single row, and there is one elevator at each side of the building. The left elevator can only go up, and the right elevator can only go down. In addition, before the rooftop signboard is turned off only the left elevator may be used, and after it is turned off only the right elevator may be used.
So the route always has the same shape. A rides the left elevator from floor 1 up to the roof, getting off at any floors along the way to turn off office lights. On reaching the roof, A turns off the signboard, which requires crossing the roof from the left end (the left elevator) all the way to the right end (the right elevator). A then rides the right elevator back down to floor 1, again getting off at any floors along the way to turn off the remaining lights.
Each office light may be turned off either on the way up (approached from the left) or on the way down (approached from the right). Whenever A steps off on a floor to turn off lights, A must walk back to the same elevator before the trip can continue.
Looking up through the windows from the janitor's room, A can see exactly which offices are still lit, so A plans the route before starting. Compute the minimum total distance A must travel to turn off every lit office and the signboard.
Distances are assumed as follows.

Input is given on standard input. The first line contains the number of test cases T (1≤T≤20).
Each test case is given as follows.
No office (same floor and same number) is given more than once.
For each test case, print on its own line the minimum total distance needed to turn off every lit office and the signboard.
The key condition is that the left elevator (going up) may be used only before the signboard is turned off, and the right elevator (going down) only after. Because of this, for every lit office you can decide independently, floor by floor, whether to turn it off while going up (from the left) or while coming down (from the right).