/** * Author: AcFunction * Date: 2019-08-24 13:43:52 * Email: 3486942970@qq.com **/ #include #define ll long long #define db double #define PII pair #define pb push_back #define fi first #define se second #define MP make_pair using namespace std; const int N = 1000000; int n, mu[N +5], fla[N + 5], p[N + 5], cnt, sum[N + 5], s[N + 5]; ll sn[N + 5], sm[N + 5]; ll F[N + 5]; void prework() { mu[1] = 1; for(int i = 2; i <= N; i++) { if(!fla[i]) p[++cnt] = i, mu[i] = -1; for(int j = 1; j <= cnt && i * p[j] <= N; j++) { fla[i * p[j]] = 1; if(i % p[j] == 0) { mu[i * p[j]] = 0; break ; } mu[i * p[j]] = mu[i] * mu[p[j]]; } } for(int i = 1; i <= N; i++) { for(int j = i; j <= N; j += i) { F[j] += mu[j / i] * mu[i]; } } // for(int i = 1; i <= N; i++) sum[i] = sum[i - 1] + mu[i]; } int main() { prework(); int Tt; scanf("%d", &Tt); while(Tt--) { int n, m; scanf("%d %d", &n, &m); ll ans = 0; if(n > m) swap(n, m); for(int T = 1; T <= m; T++) { sn[T] = sm[T] = 0; for(int i = T; i <= m; i += T) { if(i <= n) sn[T] += mu[i]; sm[T] += mu[i]; } } for(int T = 1; T <= n; T++) { // cout << sn[T] << " " << sm[T] << endl; ans += 1ll * sn[T] * sm[T] * F[T]; } printf("%I64d\n", ans); } return 0; }