import java.io.*; import java.text.NumberFormat; import java.util.*; /** * Created by VIET ANH on 27/04/2015. */ public class Main { private static int T; private static long oo=Long.MAX_VALUE; private static long base=1000000007; public static void main(String[] args) throws IOException { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int T=in.nextInt(); while (T-->0) { int n=in.nextInt(); int res=Integer.MAX_VALUE; for (int i = 1; i <= Math.sqrt(n+1); i++) { if (n%i==0) { int a=i; int b=n/i; res=Math.min(res,2*a+2*b); } } out.println(res); } out.close(); } }