#include #include #include #define fo(i,a,b) for(int i=a;i<=b;i++) #define fd(i,a,b) for(int i=a;i>=b;i--) using namespace std; typedef long long ll; const int N=1e6+5; int ty,n,m; ll a[N]; int p[N],mu[N]; bool bz[N]; void pre(int N) { mu[1]=1; fo(i,2,N) { if (!bz[i]) p[++p[0]]=i,mu[i]=-1; fo(j,1,p[0]) { int k=i*p[j];if (k>N) break; bz[k]=1;if (!(i%p[j])) break; mu[k]=-mu[i]; } } } int main() { pre(1e6); for(scanf("%d",&ty);ty;ty--) { scanf("%d%d",&n,&m);if (n>m) swap(n,m); fo(i,1,n) a[i]=0; fo(i,1,n) fo(j,1,n/i) a[i*j]+=mu[i]*mu[j]; ll ans=0; fo(t,1,n) { ll s1=0,s2=0; fo(i,1,n/t) s1+=mu[i*t]; fo(i,1,m/t) s2+=mu[i*t]; ans+=a[t]*s1*s2; } printf("%I64d\n",ans); } return 0; }