#include <iostream>
using namespace std;
int gcd(int a, int b)
{
int t, r;
if(a > b)
{
t = b;
b = a;
a = t;
}
while(a)
{
r = b % a;
b = a;
a = r;
}
return b;
}
int main()
{
int T;
cin >> T;
//gcd(a,c) == b;
//c == b * n
int a, b, c;
while(T--)
{
cin >> a >> b;
for(c = b + b; gcd(a, c) != b && c < a * b; c += b);
cout << c << endl;
}
return 0;
}