#include <stdio.h>
#include <math.h>
int count_valid_pairs(int A, int B) {
long long total_pairs = (long long)A * B;
long long count_perfect_square_pairs = 0;
for (int i = 1; i <= A; i++) {
for (int j = 1; j <= B; j++) {
long long product = (long long)i * j;
long long root = (long long)sqrt(product);
if (root * root == product) {
count_perfect_square_pairs++;
}
}
}
return total_pairs - count_perfect_square_pairs;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
int A, B;
scanf("%d %d", &A, &B);
printf("%lld\n", count_valid_pairs(A, B));
}
return 0;
}