#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 1000000 + 10;
int phi[N];
int main() {
for(int i=0; i<N; ++i)
phi[i] = i;
for(int i=2; i<N; ++i)
if(phi[i] == i)
for(int j=i; j<N; j+=i)
phi[j] -= phi[j] / i;
int m;
int t;
scanf("%d", &t);
while(t--) {
scanf("%d", &m);
printf("%lld\n", (ll)phi[m]*(m-1));
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnR5cGVkZWYgbG9uZyBsb25nIGxsOwp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBpbnQgTiA9IDEwMDAwMDAgKyAxMDsKaW50IHBoaVtOXTsKCmludCBtYWluKCkgewoJZm9yKGludCBpPTA7IGk8TjsgKytpKQoJCXBoaVtpXSA9IGk7Cglmb3IoaW50IGk9MjsgaTxOOyArK2kpCgkJaWYocGhpW2ldID09IGkpCgkJCWZvcihpbnQgaj1pOyBqPE47IGorPWkpCgkJCQlwaGlbal0gLT0gcGhpW2pdIC8gaTsKCWludCBtOwoJaW50IHQ7CglzY2FuZigiJWQiLCAmdCk7Cgl3aGlsZSh0LS0pIHsKCQlzY2FuZigiJWQiLCAmbSk7CgkJcHJpbnRmKCIlbGxkXG4iLCAobGwpcGhpW21dKihtLTEpKTsKCX0KCXJldHVybiAwOwp9