#include using namespace std; #define ge getchar() #define Re read() inline int read() { int x = 0, ch; while(!isdigit(ch = ge)) ; while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge; return x; } typedef long long ll; const int MAXN = 1000000; int tot; int pri[MAXN + 1]; int miu[MAXN + 1]; bool chk[MAXN + 1]; ll S0[MAXN + 1]; ll S1[MAXN + 1]; ll S2[MAXN + 1]; inline void init(int n) { miu[1] = 1; for(int i = 2; i <= n; i++) { if(!chk[i]) pri[++tot] = i, miu[i] = -1; for(int j = 1; j <= tot; j++) { if(i * pri[j] > n) break; chk[i * pri[j]] = 1; if(i % pri[j] == 0) break; miu[i * pri[j]] = -miu[i]; } } for(int i = 1; i <= n; i++) for(int j = i, k = 1; j <= n; j += i, ++k) S2[j] += miu[i] * miu[k]; } int main() { int T = Re; init(1000000); while(T--) { int n = Re, m = Re, mi = min(n, m); ll res = 0; for(int i = 1; i <= n; i++) for(int j = i; j <= n; j += i) S0[i] += miu[j]; for(int i = 1; i <= m; i++) for(int j = i; j <= m; j += i) S1[i] += miu[j]; for(int l = 1; l <= mi; l++) res += 1LL * S0[l] * S1[l] * S2[l]; cout << res << endl; memset(S0, 0, sizeof(S0)); memset(S1, 0, sizeof(S1)); } return 0; }