#include using namespace std; typedef long long ll ; const int N = 1000005 , M = 1000000 , mod = 998244353; int miu[N],pri[N],cnt,vis[N],n,m; ll f[N],g[N],h[N]; void init() { f[1]=miu[1]=1; for(int i=2;i<=M;i++) { if(!vis[i])pri[++cnt]=i,miu[i]=-1; for(int j=1;j<=cnt&&pri[j]*i<=M;j++) { vis[i*pri[j]]=1; if(i%pri[j]==0)break; miu[i*pri[j]]=-miu[i]; } } for(int i=2;i<=M;i++)f[i]=f[i-1]+miu[i]; } void solve() { scanf("%d%d",&n,&m); int lim = min(n,m); memset(g,0,sizeof(ll)*(n+1));memset(h,0,sizeof(ll)*(m+1)); for(int i=1;i<=n;i++)for(int j=i;j<=n;j+=i)g[i]+=miu[j]; for(int i=1;i<=m;i++)for(int j=i;j<=m;j+=i)h[i]+=miu[j]; ll ans=0; for(int i=1;i<=lim;i++) for(int j=i;j<=lim;j+=i) ans+=miu[i]*miu[j/i]*g[j]*h[j]; printf("%I64d\n",ans); } int main(){init();int T;scanf("%d",&T);while(T--)solve();}