http://acm.hdu.edu.cn/showproblem.php?pid=5608
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <set>
#include <map>
#include <tr1/unordered_map>
#include <cmath>
//#include<bits/stdc++.h>
using namespace std;
#define sfi(i) scanf("%d",&i)
#define sfl(i) scanf("%I64d",&i)
#define sfs(i) scanf("%s",(i))
#define pri(i) printf("%d\n",i)
#define prl(i) printf("%I64d\n",i)
#define sff(i) scanf("%lf",&i)
#define ll long long
#define ull unsigned long long
#define mem(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define eps 1e-10
#define PI acos(-1.0)
#define lowbit(x) ((x)&(-x))
#define fl() printf("flag\n")
#define MOD(x) ((x%mod)+mod)%mod
#define endl '\n'
#define pb push_back
#define lson (rt<<1)
#define rson (rt<<1|1)
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
template<typename T>inline void read(T &x)
{
x=0;
static int p;p=1;
static char c;c=getchar();
while(!isdigit(c)){if(c=='-')p=-1;c=getchar();}
while(isdigit(c)) {x=(x<<1)+(x<<3)+(c-48);c=getchar();}
x*=p;
}
const int maxn=5e6+9;
const int mod=1e9+7;
tr1::unordered_map<ll,ll>w1;
//tr1::unordered_map<int,ll>w2;
bool check[maxn+10];
int prime[maxn+10];
int mu[maxn+10];
//int phi[maxn+10];
ll g[maxn+10],f[maxn+10];
ll sum1[maxn+10];
//ll sum2[maxn+10];
ll power(ll x,ll n)
{
ll ans=1;
while(n)
{
if(n&1) ans=ans*x%mod;
x=x*x%mod;
n>>=1;
}
return ans;
}
void Mobius_phi(int N)
{
mem(check,0);
mu[1]=1;
//phi[1]=1;
int tot=0;
for(int i=2;i<=N;i++)
{
if(!check[i])
{
prime[tot++]=i;
mu[i]=-1;
//phi[i]=i-1;
}
for(int j=0;j<tot;j++)
{
if(i*prime[j]>N) break;
check[i*prime[j]]=true;
if(i%prime[j]==0)
{
mu[i*prime[j]]=0;
//phi[i*prime[j]]=(ll)phi[i]*prime[j]%mod;
break;
}
else
{
mu[i*prime[j]]=-mu[i];
//phi[i*prime[j]]=(ll)phi[i]*(prime[j]-1)%mod;
}
}
}
for(int i=1;i<=N;i++)
{
g[i]=(ll)(i-1)*(i-2)%mod;
}
for(int i=1;i<=N;i++)
{
for(int j=i;j<=N;j+=i)
{
f[j]=(f[j]+mu[i]*g[j/i])%mod;
while(f[j]<0) f[j]+=mod;
}
}
for(int i=1;i<=N;i++) sum1[i]=(sum1[i-1]+f[i])%mod;
}
//ll inv4=power(4LL,mod-2);
ll inv6=power(6LL,mod-2);
ll inv2=power(2LL,mod-2);
//
ll S2(ll n)
{
n%=mod;
while(n<0) n+=mod;
return n*(n+1)%mod*(2*n+1)%mod*inv6%mod;
}
//
//ll S3(ll n)
//{
// n%=mod;
// while(n<0) n+=mod;
// return n*n%mod*(n+1)%mod*(n+1)%mod*inv4%mod;
//}
//
ll S1(ll n)
{
n%=mod;
while(n<0) n+=mod;
return n*(n+1)%mod*inv2%mod;
}
ll djsmu(ll n)
{
if(n<=1000000) return sum1[n]%mod;
if(w1[n]) return w1[n];
ll ans=S2(n)-3*S1(n)+2*n;
ans%=mod;
while(ans<0) ans+=mod;
for(ll l=2,r;l<=n;l=r+1)
{
r=n/(n/l);
ans-=(r-l+1)*djsmu(n/l)%mod;
while(ans<0) ans+=mod;
}
w1[n]=ans;
return ans;
}
//ll djsphi(ll n)
//{
// if(n<=1000000) return sum2[n]%mod;
// if(w2[n]!=0) return w2[n];
// ll ans=S2(n)-S1(n)+2*n;
// ans%=mod;
// while(ans<0) ans+=mod;
// for(ll l=2,r;l<=n;l=r+1)
// {
// r=n/(n/l);
// ans-=(r-l+1)*djsphi(n/l)%mod;
// while(ans<0) ans+=mod;
// }
// return w2[n]=ans;
//}
int main()
{
//FAST_IO;
//freopen("input.txt","r",stdin);
//cout<<inv2<<" "<<inv6<<endl;
Mobius_phi(1000000);
int T;
read(T);
while(T--)
{
ll n;
read(n);
ll ans=0;
ans=djsmu(n);
printf("%lld\n",ans);
}
return 0;
}