The police have received a message that a bomb has been placed in the city's tallest building. A crisis team is formed and decides to evacuate the building as fast as possible. Luckily it is past five, so most people have already left. Using the building's security cameras, the crisis team can list the people still inside and the floors where they are.
The crisis team decides to use a single elevator for the evacuation, and this elevator happens to be at the top floor of the building. To minimize the risk of the bomb being triggered by the elevator's vibrations, the elevator will only move down, and it will move down only once. Over the intercom, everyone is asked to take the stairs (up or down) to the floor where the elevator will pick them up; the elevator is located right next to the stairs. Some people on the lower floors may instead leave the building using only the stairs.
The elevator needs a constant time to move down one floor and a constant time to close its doors (the time to open the doors is ignored). A person needs a constant time to walk one floor up or down the stairs. At the very beginning, the elevator's doors are closed.
Write a program that finds the fastest evacuation plan and reports how quickly everybody can reach the ground floor (floor $0$).
The first line contains a single integer: the number of test cases. Each test case has the following format:
You may assume that all of the people involved fit into the elevator at once.
For every test case, print a single line with one integer: the time needed to get everybody in the building down to the ground floor (floor $0$).