#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
int n;
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
int ans = 2*(n+1);
for(int i = 1; i*i <=n;i++){
if(n % i == 0)
ans = min(ans,2*(i + n/i));
}
printf("%d\n",ans);
}
return 0;
}