#include <bits/stdc++.h>
using namespace std;
typedef vector<int> VI;
typedef pair <int,int> ii;
typedef long long LL;
#define pb push_back
const int INF = 2147483647;
const int N = 1000005;
int y, a, i, z;
VI v;
LL x;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> z;
while(z--) {
cin >> x >> y;
v.clear();
a = x;
for (i=2;i*i<=a;i++) if (a % i == 0) {
while (a % i == 0) {
a /= i;
v.pb(i);
}
}
if (a > 1) v.pb(a);
while (y > 0 && v[0] != v.back()) {
x *= v[0];
y--;
//cout << " " << x << endl;
if (y > 0) {
x /= v.back();
v.pop_back();
y--;
}
//cout << x << endl;
}
if (y % 2 == 1) x *= v[0];
cout << x << endl;
}
return 0;
}