P17264 [ICPC 2017 Urumqi R] Gathering

Description

In the game of Starcraft, Terran has $1$ idle base, $4$ idle workers, $6$ supplies and $50$ minerals at the beginning. When a worker is idle, the worker can choose one of the following $3$ things to do. * Gathering minerals: It will cost nothing, and the worker will be busy for $10$ seconds. After that, the minerals will increase by $8$ and the worker will be idle again. * Building a supply depot: It will cost $100$ minerals immediately, and the worker will be busy for $30$ seconds. After that, the supplies will increase by $8$ and the worker will be idle again. * Building a base: It will cost $400$ minerals immediately, and the worker will be busy for $120$ seconds. After that, a new idle base will be created, and the supplies will increase by $10$, and the worker will be idle again. When a base is idle, it can cost $50$ minerals and $1$ supply immediately, and it will be busy for $20$ seconds. After that, an idle worker will be created and the base will be idle again. The amount of minerals and supplies cannot be negative all the time. That is, we must have enough minerals and supplies to be cost before doing anything. Your task is to reach $m$ minerals as soon as possible.

Input Format

The first line is the number of test cases which is up to $52$. For each test case, there is a line containing only 1 integer $m (m < 2^{64})$.

Output Format

For each test case, output the minimum time to reach $m$ minerals.