// Write nodeour code here
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define mp make_pair
#define pb(a) push_back(a)
#define pp pop_back()
#define all(v) (v.begin(), v.end())
#define alar (a + 1, a + 1 + n)
#define ff first
#define ss second
#define sz(a) (int)(a.size())
#define ffor(i, a, b) for (int i = a; i <= b; i++)
#define rloop(i, c, d) for (int i = c; i >= d; i--)
#define ll long long
#define vc vector<ll>
#define pii pair<ll, ll>
#define mii map<ll, ll>
#define mod 1000000007
#define MAX 100000
#define endl "\n"
#define o(x) cout << x << endl
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod2 = 998244353;
void solve()
{
ll x;
int p;
cin >> x >> p;
ll ans = x;
rloop(i, 100000, 1)
{
ll val = 1;
bool flag = true;
ffor(j, 1, p)
{
if (val * i * 1LL > x)
{
flag = false;
break;
}
val = val * i * 1LL;
}
if (flag)
{
ll store = (1LL * (val * (x / (__gcd(x, val)))));
ll val1 = __gcd(val, x);
if ((store)% val1 == 0)
{
ans = min(ans, store/val1);
// x = ans;
}
}
}
if (p == 1)
{
o(1);
return;
}
o(ans);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
ffor(l, 1, t)
{
// cout << "Case #" << l << ":"
// << " ";
solve();
}
return 0;
}
Ci8vIFdyaXRlIG5vZGVvdXIgY29kZSBoZXJlCiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgoKLy8jaW5jbHVkZSA8ZXh0L3BiX2RzL2Fzc29jX2NvbnRhaW5lci5ocHA+Ci8vI2luY2x1ZGUgPGV4dC9wYl9kcy90cmVlX3BvbGljeS5ocHA+CiNkZWZpbmUgbXAgbWFrZV9wYWlyCiNkZWZpbmUgcGIoYSkgcHVzaF9iYWNrKGEpCiNkZWZpbmUgcHAgcG9wX2JhY2soKQojZGVmaW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ICAgIGJvb2wgZmxhZyA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGZmb3IoaiwgMSwgcCkKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBpZiAodmFsICogaSAqIDFMTCA+IHgpCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZmxhZyA9IGZhbHNlOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBicmVhazsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB2YWwgPSB2YWwgKiBpICogMUxMOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmIChmbGFnKQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGxsIHN0b3JlID0gKDFMTCAqICh2YWwgKiAoeCAvIChfX2djZCh4LCB2YWwpKSkpKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbGwgdmFsMSA9IF9fZ2NkKHZhbCwgeCk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGlmICgoc3RvcmUpJSB2YWwxID09IDApCgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGFucyA9IG1pbihhbnMsIHN0b3JlL3ZhbDEpOwogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gIHggPSBhbnM7CiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgIGlmIChwID09IDEpCiAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbygxKTsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgIG8oYW5zKTsKfQoKaW50IG1haW4oKQp7CiAgICAgICAgICAgICAgIGlvc19iYXNlOjpzeW5jX3dpdGhfc3RkaW8oZmFsc2UpOwogICAgICAgICAgICAgICBjaW4udGllKE5VTEwpOwogICAgICAgICAgICAgICBjb3V0LnRpZShOVUxMKTsKICAgICAgICAgICAgICAgaW50IHQ7CiAgICAgICAgICAgICAgIGNpbiA+PiB0OwogICAgICAgICAgICAgICBmZm9yKGwsIDEsIHQpCiAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgLy8gY291dCA8PCAiQ2FzZSAjIiA8PCBsIDw8ICI6IgogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAvLyAgICAgIDw8ICIgIjsKICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc29sdmUoKTsKICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICByZXR1cm4gMDsKfQ==