#include #include int main(){ int n,t,i,j,c; scanf("%d",&t); while(t--){ scanf("%d",&n); c=sqrt(n); for(i=c;i>=1;i++){ if(n%i==0)break; } printf("%d\n",2*(i+(n/i))); } return 0; }