#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main() {
int t, n, a, b, r;
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
a=sqrt(n); b=r=0;
for(int i=a; i>0;) {
if(n%i!=0) i--;
else {
b=n/i; r=b-i; break;
}
}
printf("%d\n", r);
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Y3N0ZGlvPgojaW5jbHVkZSA8Y21hdGg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpIHsKCWludCB0LCBuLCBhLCBiLCByOwoJc2NhbmYoIiVkIiwgJnQpOwoJd2hpbGUodC0tKSB7CgkJc2NhbmYoIiVkIiwgJm4pOwoJCWE9c3FydChuKTsgYj1yPTA7CgkJZm9yKGludCBpPWE7IGk+MDspIHsKCQkJaWYobiVpIT0wKSBpLS07CgkJCWVsc2UgewoJCQkJYj1uL2k7IHI9Yi1pOyBicmVhazsKCQkJfQoJCX0KCQlwcmludGYoIiVkXG4iLCByKTsKCX0KCXJldHVybiAwOwp9