#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;
const int MX = 1e6 + 5;
int mu[MX];
char prime[MX];
void sieve(){
mu[1] = 1;
for(int i = 2; i< MX; i++) mu[i] = -1, prime[i] = 1;
for(int i = 2; i<MX; i++){
if(prime[i]){
mu[i] = 1;
for(int j = 2 * i; j < MX; j += i){
prime[j] = 0;
mu[j] = (j % (i * i)) == 0 ? 0 : -mu[j];
}
}
}
}
int main() {
sieve();
int t;
ll n, m;
scanf("%d", &t);
for(int i = 1; i<=t; i++){
scanf("%lld %lld", &n, &m);
if(n > m) swap(n, m);
ll Ans = n * m;
for(int i = 2; i<=n; i++){
Ans -= (ll)mu[i] * (ll)(n/i) * (ll)(m/i);
}
printf("%lld\n", Ans);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIHNpZ25lZCBsb25nIGxvbmcgbGw7CmNvbnN0IGludCBNWCA9IDFlNiArIDU7CmludCBtdVtNWF07CmNoYXIgcHJpbWVbTVhdOwoKdm9pZCBzaWV2ZSgpewoJbXVbMV0gPSAxOwoJZm9yKGludCBpID0gMjsgaTwgTVg7IGkrKykgbXVbaV0gPSAtMSwgcHJpbWVbaV0gPSAxOwoJZm9yKGludCBpID0gMjsgaTxNWDsgaSsrKXsKCQlpZihwcmltZVtpXSl7CgkJCW11W2ldID0gMTsKCQkJZm9yKGludCBqID0gMiAqIGk7IGogPCBNWDsgaiArPSBpKXsKCQkJCXByaW1lW2pdID0gMDsKCQkJCW11W2pdID0gKGogJSAoaSAqIGkpKSA9PSAwID8gMCA6IC1tdVtqXTsKCQkJfQoJCX0KCX0KfQoKaW50IG1haW4oKSB7CglzaWV2ZSgpOwoJaW50IHQ7CglsbCBuLCBtOwoJc2NhbmYoIiVkIiwgJnQpOwoJCglmb3IoaW50IGkgPSAxOyBpPD10OyBpKyspewoJCXNjYW5mKCIlbGxkICVsbGQiLCAmbiwgJm0pOwoJCWlmKG4gPiBtKSBzd2FwKG4sIG0pOwoJCWxsIEFucyA9IG4gKiBtOwoJCWZvcihpbnQgaSA9IDI7IGk8PW47IGkrKyl7CgkJCUFucyAtPSAobGwpbXVbaV0gKiAobGwpKG4vaSkgKiAobGwpKG0vaSk7CgkJfQoJCXByaW50ZigiJWxsZFxuIiwgQW5zKTsKCX0KCXJldHVybiAwOwp9