#include<iostream>
using namespace std;
const int N=1e7;
long phi[N+1];
bool isp[N+1];
int main()
{
	for(int i=1;i<=N;i++)
	{
		phi[i]=i;
		isp[i]=true;
	}
	for(int p=2;p<=N;p++)if(isp[p])
	{
		for(int i=p;i<=N;i+=p)
		{
			phi[i]=phi[i]/p*(p-1);
			isp[i]=false;
		}
	}
	for(int i=1;i<N;i++)phi[i+1]+=phi[i];
	int T;cin>>T;
	for(;T--;)
	{
		int n;cin>>n;
		cout<<(long)n*(n-1)-phi[n]+1<<"\n";
	}
}