var t,n,i:longint; begin readln(t); while t>0 do begin readln(n); for i:=trunc(sqrt(n)) downto 1 do if n mod i=0 then begin writeln(2*(i+n div i)); break; end; dec(t); end; end.