/**
* Author : As_Shejan
* Created: 2024-09-06 18:38:20
**/
#include <bits/stdc++.h>
using namespace std;
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define vi vector<ll>
#define pi pair<ll, ll>
#define vp vector<pair<ll, ll>>
#define f first
#define sc second
#define all(x) x.begin(), x.end()
#define en '\n'
#define YES cout << "YES" << en
#define NO cout << "NO" << en
#define yes cout << "Yes" << en
#define no cout << "No" << en
#define fill_number(x, n) setfill('0') << setw(n) << (x)
#define precision_number(x, n) fixed << setprecision(n) << (x)
template <typename T>
T gcd(T a, T b)
{
while (b != 0)
{
int temp = b;
b = a % b;
a = temp;
}
return a;
}
template <typename T>
T lcm(T a, T b)
{
return (a * (b / gcd(a, b)));
}
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
int32_t main()
{
FastIO;
ll t;
cin >> t;
while(t--)
{
ll a , b;
cin>>a>>b;
ll count = 0;
for(ll i = 1; i<=a ;i++){
for(ll j = 1; j <= b; j++){
if( lcm(i, j) != gcd(i, j) ){
count++;
}
}
}
cout<<count<<en;
}
return 0;
}