//Bismillahir Rahmanir Rahim
/******Harun Or Rashid******/
/***********Template Starts Here***********/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<cassert>
#include<string>
#include<vector>
#include<set>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
using namespace std;
#define MEM(a,b) memset(a,b,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)>(b)?(b):(a))
#define ABS(a) ((a)>0? (a):(-(a)))
#define SQ(a) ((a)*(a))
#define SZ(a) (int)a.size()
#define FORN(i,n) for(i=1;i<=n;i++)
#define FORAB(i,a,b) for(i=a;i<=b;i++)
#define ALL(V) V.begin(),V.end()
#define pb(a) push_back(a)
#define pr(a) cout<<a<<endl
#define SQR(a) ((a)*(a))
#define pf printf
#define sf scanf
#define swap(a,b) (a ^= b, b ^= a, a ^= b)
#define PI acos(-1)
#define x first
#define y second
#define eps 1e-7
typedef int D;
typedef long long int LLD;
typedef unsigned long long int LLU;
typedef vector<D> VI;
typedef set<D> SI;
typedef vector<D>::iterator Viti;
/***********Template Ends Here***********/
int phi(int n)
{
if(n<3) return 1;
int result=n;
if(n%2==0)
{
result-=result/2;
while(n%2==0) n/=2;
}
for(int i=3; i*i<=n; i+=2)
{
if(n%i==0)
{
result-=result/i;
while(n%i==0) n/=i;
}
}
if(n>1) result-=result/n;
return result;
}
int main()
{
int T,n;
cin>>T;
while(T--)
{
cin>>n;
cout<<phi(n)<<endl;
}
return 0;
}
Ly9CaXNtaWxsYWhpciBSYWhtYW5pciBSYWhpbQovKioqKioqSGFydW4gT3IgUmFzaGlkKioqKioqLwovKioqKioqKioqKipUZW1wbGF0ZSBTdGFydHMgSGVyZSoqKioqKioqKioqLwojaW5jbHVkZTxpb3N0cmVhbT4KI2luY2x1ZGU8Y3N0ZGlvPgojaW5jbHVkZTxjc3RyaW5nPgojaW5jbHVkZTxjbWF0aD4KI2luY2x1Z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