#include<bits/stdc++.h>#define reg registertypedeflonglong ll;intread(){char c;int s =0, flag =1;while((c=getchar())&&!isdigit(c))if(c =='-'){ flag =-1, c =getchar();break;}while(isdigit(c)) s = s*10+ c-'0', c =getchar();return s * flag;}constint maxn =1e6+5;constint lim =1e6;int N;int M;int pc;int p[maxn];int mu[maxn];int s2[maxn];int s3[maxn];int vis[maxn];int s1[maxn+1];voidInit(){
mu[1]=1;for(reg int i =2; i <= lim; i ++){if(!vis[i]) p[++ pc]= i, mu[i]=-1;for(reg int j =1; j <= pc && p[j]*i <= lim; j ++){
vis[p[j]*i]=1;if(i % p[j]==0){ mu[p[j]*i]=0;break;}
mu[p[j]*i]=-mu[i];}}for(reg int i =1; i <= lim; i ++)for(reg int j =1; j <= lim/i; j ++) s1[i*j]+= mu[i]* mu[j];}voidWork(){memset(s2,0,sizeof s2);memset(s3,0,sizeof s3);
N =read(), M =read();for(reg int i =1; i <= N; i ++)for(reg int j =1; j <= N/i; j ++) s2[i]+= mu[i * j];for(reg int i =1; i <= M; i ++)for(reg int j =1; j <= M/i; j ++) s3[i]+= mu[i * j];
N = std::min(N, M);
ll Ans =0;for(reg int i =1; i <= N; i ++) Ans +=1ll*s1[i]*s2[i]*s3[i];printf("%lld
", Ans);}intmain(){Init();int test_cnt =read();while(test_cnt --)Work();return0;}