#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int Mod=998244353;

void solve() {

    ll a,b;
    cin >> a >> b;
    
    if(b%a==0){ 
        cout << b*b/a << '\n';
        return;
    }

    cout << __gcd(a,b)/a*b << '\n';
}

int main(){ 
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
	
    int t;
    cin >> t;
    while (t--) solve();
    

    return 0;
}
