//51nod 1584 加权约数和
#include<bits/stdc++.h>
#define N 1000000
#define ll long long
#define M(a) memset(a,0,sizeof a)
#define fo(i,j,k) for(i=j;i<=k;i++)
using namespace std;
const int mxn=1000001;
const int mod=1e9+7;
int n,m,T;
bool vis[mxn];
int s[mxn],ss[mxn],miu[mxn],pri[mxn];
int ans[mxn],g[mxn],c[mxn];
inline int read()
{
int x=0;char ch=getchar();
while(ch<'0'||ch>'9') ch=getchar();
while(ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
return x;
}
inline int ksm(int x,int k)
{
int b=x;--k;
while(k)
{
if(k&1) x=(ll)x*b%mod;
b=(ll)b*b%mod,k>>=1;
}
return x;
}
inline int get(int x,int p)
{
int cnt=0,tmp=x;
while(tmp%p==0) cnt++,tmp/=p;
int t=ksm(p,2*cnt+1)-1;
if(!c[p-1]) c[p-1]=ksm(p-1,mod-2);
t=(ll)t*c[p-1]%mod;
return (ll)g[tmp]*t%mod;
}
inline void init()
{
int i,j;
miu[1]=g[1]=1;
fo(i,2,N)
{
if(!vis[i])
pri[++pri[0]]=i,miu[i]=-1,g[i]=(1+i+(ll)i*i%mod)%mod;
for(int j=1;j<=pri[0] && (ll)i*pri[j]<=N;j++)
{
vis[i*pri[j]]=1;
if(i%pri[j]==0)
{
g[i*pri[j]]=get(i*pri[j],pri[j]);
break;
}
miu[i*pri[j]]=-miu[i];
g[i*pri[j]]=(ll)g[i]*g[pri[j]]%mod;
}
}
for(i=1;i<=N;i++) for(j=i;j<=N;j+=i)
{
s[j]=s[j]+i;
if(s[j]>mod) s[j]-=mod;
}
fo(i,1,N)
{
ss[i]=(ss[i-1]+s[i])%mod;
if(ss[i]>mod) ss[i]-=mod;
}
for(i=1;i<=N;i++) if(miu[i]) for(j=i;j<=N;j+=i)
{
ans[j]=ans[j]+(ll)i*j*miu[i]%mod*s[j/i]%mod*ss[j/i]%mod;
if(ans[j]<0) ans[j]+=mod;
else if(ans[j]>mod) ans[j]-=mod;
}
fo(i,1,N)
{
ans[i]=ans[i]+ans[i-1];
if(ans[i]>mod) ans[i]-=mod;
}
fo(i,1,N) g[i]=(ll)i*g[i]%mod;
fo(i,1,N)
{
g[i]=g[i-1]+g[i];
if(g[i]>mod) g[i]-=mod;
}
}
int main()
{
init();
int i,j;
T=read();
fo(i,1,T)
{
n=read();
printf("Case #%d: %d\n",i,(2*ans[n]%mod-g[n]+mod)%mod);
}
return 0;
}