#include using namespace std; const int N = 1000005; int mu[N], pri[N], tot, zhi[N]; inline void get_mu(int n) { zhi[1] = mu[1] = 1; tot = 0; for (int i = 2; i <= n; i++) { if (!zhi[i]) pri[++tot] = i, mu[i] = -1; for (int j = 1; j <= tot && i * pri[j] <= n; j++) { zhi[i * pri[j]] = 1; if (i % pri[j]) mu[i * pri[j]] = -mu[i]; else { mu[i * pri[j]] = 0; break; } } } } int f[N], g[N]; int main() { get_mu(1000000); int T; scanf("%d", &T); while (T--) { int n, m; scanf("%d%d", &n, &m); if (n > m) swap(n, m); for (int i = 1; i <= n; i++) { f[i] = 0; for (int j = i; j <= n; j += i) f[i] += mu[j]; } for (int i = 1; i <= m; i++) { g[i] = 0; for (int j = i; j <= m; j += i) g[i] += mu[j]; } long long ans = 0; for (int i = 1; i <= n; i++) if (mu[i]) { long long sum = 0; for (int j = 1, _ = n / i; j <= _; j++) { sum += 1ll * mu[j] * f[i * j] * g[i * j]; } sum *= mu[i]; ans += sum; } cout << ans << endl; } return 0; }