def get_mobius(N):
prime_vals = []
flag = [True] * (N+1)
mobius = [0] * (N+1)
mobius[1] = 1
for val in range(2, N+1):
if flag[val]:
prime_vals.append(val)
mobius[val] = -1
for p_val in prime_vals:
if val * p_val > N:
break
flag[val * p_val] = False
if val % p_val == 0:
mobius[val * p_val] = 0
break
else:
mobius[val * p_val] = 0 - mobius[val]
return mobius
# 莫比乌斯函数的前缀和
M = get_mobius(50010)
for i in range(2, 50010):
M[i] += M[i-1]
# h(n) = n//1 + n//2 + ..... n//n
def h(n):
if n == 0:
return 0
i = 1
tot = 0
while i <= n:
end = n // (n // i)
tot += (end - i + 1) * (n // i)
i = end + 1
return tot
H = [h(i) for i in range(50010)]
# 1 <= i <= MM 且 1 <= j <= NN 的所有数对(i, j)中,i*j的约数个数的和
def solve(MM, NN):
tot = 0
i = 1
while i<=MM and i<=NN:
a_end, b_end = MM//(MM//i), NN//(NN//i)
end = min(a_end, b_end)
aa, bb = H[MM//i], H[NN//i]
if aa == 0 or bb == 0:
break
tot += (M[end] - M[i-1]) * aa * bb
i = end + 1
return tot
T = int(input())
for _ in range(T):
MM, NN = map(int, input().split())
print(solve(MM, NN))