Under construction

Still being built. Things may change

Connecting Square Tiles

Time limit1sMemory limit1024 MB

Summary
Given N unit square tiles, find the minimum perimeter of one connected figure formed by placing them on a grid without overlap.
Level

Medium4 of 10

Topics
Math, Implementation
Solved
No attempts yet

Problem

Given NN square tiles, all with the same shape and size, each with side length 11. There is a floor covered with a grid of unit squares. Join the tiles on this floor to form a single figure.

Tiles can only be placed on the cells of the grid, and tiles cannot overlap or be stacked. All tiles must be connected to each other.

Given the number of square tiles, find the minimum possible perimeter of a figure that can be formed by joining them according to the rules above. You must solve TT test cases in one input.

Input

The first line contains the number of test cases TT. (1≤T≤100 0001\leq T\leq 100\,000)

Each of the next TT lines contains the number of tiles NN for one test case. (1≤N≤1091\leq N\leq 10^9)

The input data can be large, so keep this in mind.

Output

For each test case, in the order given, print the minimum possible perimeter on its own line.

Hint

This is a problem where the same task is solved many times within one input. To be accepted, the program must print correct answers for every test case in the input within the time limit, then exit.

Examples1

  1. Example 1

    Input
    3
    2
    3
    4
    
    Expected output
    6
    8
    8