#include <bits/stdc++.h>
using namespace std;
#define int long long
vector<bool> prime_bool;
vector<int> prime;
vector<int> spf;
//seive algo for prime no.s
void find_prime(int n){
int rest = n + 10;
prime_bool.assign(rest, true);
spf.assign(n+1, -1);
for(int i=2;i*i<=rest;i++){
if(prime_bool[i]==false) continue;
else{
for(int j=2*i;j<=rest;j+=i){
prime_bool[j]=false;
if(spf[j]==-1) spf[j] = i;
}
}
}
for(int i=2;i<=rest;i++){
if(prime_bool[i]==true){
spf[i] = i;
prime.push_back(i);
}
}
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int q;
cin>>q;
find_prime(1e6+5);
while(q--){
int a, b;
cin>>a>>b;
map<int, int> fact;
while(a>1){
fact[spf[a]]++;
a /= spf[a];
}
while(b>1){
fact[spf[b]]++;
b /= spf[b];
}
int ans = 1;
for(auto i: fact){
ans *= (2*i.second + 1); //2 is multiplied as we have to calculte for the square
}
cout<<ans<<"\n";
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgaW50IGxvbmcgbG9uZwoKdmVjdG9yPGJvb2w+IHByaW1lX2Jvb2w7CnZlY3RvcjxpbnQ+IHByaW1lOwp2ZWN0b3I8aW50PiBzcGY7Ci8vc2VpdmUgYWxnbyBmb3IgcHJpbWUgbm8ucwp2b2lkIGZpbmRfcHJpbWUoaW50IG4pewogICAgaW50IHJlc3QgPSBuICsgMTA7CiAgICBwcmltZV9ib29sLmFzc2lnbihyZXN0LCB0cnVlKTsKICAgIHNwZi5hc3NpZ24obisxLCAtMSk7CiAgICBmb3IoaW50IGk9MjtpKmk8PXJlc3Q7aSsrKXsKICAgICAgICBpZihwcmltZV9ib29sW2ldPT1mYWxzZSkgY29udGludWU7CiAgICAgICAgZWxzZXsKICAgICAgICAgICAgZm9yKGludCBqPTIqaTtqPD1yZXN0O2orPWkpewogICAgICAgICAgICAgICAgcHJpbWVfYm9vbFtqXT1mYWxzZTsKICAgICAgICAgICAgICAgIGlmKHNwZltqXT09LTEpIHNwZltqXSA9IGk7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBmb3IoaW50IGk9MjtpPD1yZXN0O2krKyl7CiAgICAgICAgaWYocHJpbWVfYm9vbFtpXT09dHJ1ZSl7CiAgICAgICAgICAgIHNwZltpXSA9IGk7CiAgICAgICAgICAgIHByaW1lLnB1c2hfYmFjayhpKTsKICAgICAgICB9CiAgICB9Cn0KCmludDMyX3QgbWFpbigpewogICAgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKE5VTEwpOwogICAgaW50IHE7CiAgICBjaW4+PnE7CiAgICBmaW5kX3ByaW1lKDFlNis1KTsKICAgIHdoaWxlKHEtLSl7CiAgICAgICAgaW50IGEsIGI7CiAgICAgICAgY2luPj5hPj5iOwogICAgICAgIG1hcDxpbnQsIGludD4gZmFjdDsKICAgICAgICB3aGlsZShhPjEpewogICAgICAgICAgICBmYWN0W3NwZlthXV0rKzsKICAgICAgICAgICAgYSAvPSBzcGZbYV07CiAgICAgICAgfQogICAgICAgIHdoaWxlKGI+MSl7CiAgICAgICAgICAgIGZhY3Rbc3BmW2JdXSsrOwogICAgICAgICAgICBiIC89IHNwZltiXTsKICAgICAgICB9CiAgICAgICAgaW50IGFucyA9IDE7CiAgICAgICAgZm9yKGF1dG8gaTogZmFjdCl7CiAgICAgICAgICAgIGFucyAqPSAoMippLnNlY29uZCArIDEpOyAgLy8yIGlzIG11bHRpcGxpZWQgYXMgd2UgaGF2ZSB0byBjYWxjdWx0ZSBmb3IgdGhlIHNxdWFyZQogICAgICAgIH0KICAgICAgICBjb3V0PDxhbnM8PCJcbiI7CiAgICB9Cn0=