A band of pirates has captured a merchant ship. The ship is too badly damaged to sail, so its entire cargo must be moved to the pirate ship.
A single plank is laid between the two ships. Any pirate can cross it to move from one ship to the other, but the plank can support only one pirate at a time.
Every pirate repeats the following four steps:
For each pirate, every one of these four steps always takes a fixed amount of time. A pirate keeps repeating the routine until there is nothing left to collect on the merchant ship.
Plank rules:
How much time passes between the moment the first pirate starts crossing the plank and the moment the last item has been carried across to the pirate ship?
The first line contains one integer: the number of test cases. Each test case has the following format:
At the start, all pirates are queued at the plank on the pirate ship in the order given in the input; the first pirate listed is the first to cross.
For each test case, print one line with a single integer: the number of seconds between the moment the first pirate begins crossing the plank and the moment the last item is carried across to the pirate ship (that is, when the final return crossing completes).