#include using namespace std; typedef long long ll; const int maxn=1000000; int p[maxn+10],mou[maxn+10],mi[maxn+10]; bool q[maxn+10]; ll uu[maxn+10]; void init() { mou[1]=1; int cnt=0; for(int i=2;i<=maxn;i++) { if( !q[i] ){ p[++cnt]=i; mou[i]=-1; } for(int j=1;j<=cnt&&i*p[j]<=maxn;j++) { q[i*p[j]]=1;mi[i*p[j]]=p[j]; if( i%p[j]==0 ){ mou[i*p[j]]=0; break; } mou[i*p[j]]=-mou[i]; } } } int main(){ init(); int tt;scanf("%d",&tt); for (int i=1;i<=maxn;i++) for (int j=1;i*j<=maxn;j++) uu[i*j]+=mou[i]*mou[j]; for (;tt--;){ int n,m;scanf("%d%d",&n,&m); ll ans=0; for (int i=1;i<=min(n,m);i++){ int nv=0,mv=0; for (int j=i;j<=n;j+=i) nv+=mou[j]; for (int j=i;j<=m;j+=i) mv+=mou[j]; ans+=uu[i]*nv*mv; } printf("%I64d\n",ans); } }