// Arup Guha
// 3/25/2013
// Solution to FHSPS Playoff Problem Cake

import java.util.*;

public class cake {

	public static void main(String[] args) {

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		for (int loop=0; loop<numCases; loop++) {
			int n = stdin.nextInt();
			System.out.println(minPerimeter(n));
		}
	}

	// Determines the minimum perimeter of a rectangle with area n square units
	// with integral sides (in units).
	public static int minPerimeter(int n) {

		// The closer to a square, the better, so try from the square root of n down.
		// The first solution we get is the best.
		for (int div = (int)(Math.sqrt(n)+1e-10); div>=1; div--)
			if (n%div == 0)
				return 2*(div + n/div);

		// Should never get here, but the compiler complains without it.
		return 2*(n+1);
	}
}