#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using vi = vector<int>;
using vll = vector<long long int>;
using vd = vector<double>;
using vvi = vector<vi>;
int ctoi(char c) { return c - '0'; }
int slen(string s) { return s.length(); }
int vsize(vi a) { return (int)a.size(); }
int in() {
  int x;
  cin >> x;
  return x;
}
long long int n;
void kmin(long long int n, long long int m) {
  long long int val = n / m;
  n = n - (val * m);
  long long int val1 = (m - n) * (val - 1) * (val) / 2;
  long long int val2 = n * val * (val + 1) / 2;
  long long int val3 = val1 + val2;
  cout << val3 << " ";
}
void kmax(long long int n, long long int m) {
  n = n - (m - 1);
  long long int val = n * (n - 1) / 2;
  cout << val;
  cout << endl;
}
const int M = 1000000;
long long int prime(long long int x) {
  for (long long int i = 2; i * i <= x; i++) {
    if (x % i == 0) return i;
  }
  return x;
}
vector<pair<long long int, long long int>> v;
set<long long int> s;
bool check(long long int x) {
  for (int i = 1; i < n; i++) {
    if (v[i].first % x != 0 && v[i].second % x != 0) {
      return 0;
    }
  }
  return 1;
}
void get_prime(long long int x) {
  if (x % 2 == 0) s.insert(2);
  while (x % 2 == 0) x = x / 2;
  for (int i = 3; i <= sqrt(x); i += 2) {
    if (x % i == 0) {
      s.insert(i);
      while (x % i == 0) x = x / i;
    }
  }
  if (x > 2) {
    s.insert(x);
  }
}
vll ar[1000000];
set<long long int> cycle;
vll path;
bool vis[1000000];
int isp(int x) {
  if (x < 2) return 0;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return 0;
  return 1;
}
void dfs(int n, int m, int x, int y, bool visited[105][105]) {
  if (x >= n || y >= m || x < 0 || y < 0 || visited[x][y]) return;
  visited[x][y] = true;
  cout << x + 1 << " " << y + 1 << "\n";
  for (int i = 0; i < n; i++) dfs(n, m, i, y, visited);
  for (int i = 0; i < m; i++) dfs(n, m, x, i, visited);
}
long long int MAXN = 3e5 + 7;
long long int sumofdigits(long long int n) {
  long long int result = 0;
  while (n > 0) {
    result += n % 10;
    n = n / 10;
  }
  return result;
}
long long int MOD = 1e9 + 7;
long long int memo[1010][1010][2];
long long int fly(long long int n, long long int cur, long long int dir,
                  long long int f) {
  if (f == 1 || cur == 0 || cur == n + 1) return 0;
  if (memo[cur - 1][f - 1][dir] != -1) {
    return memo[cur - 1][f - 1][dir - 1];
  }
  long long int tans = 0;
  if (dir == 0) {
    tans = (tans + fly(n, cur + 1, 0, f)) % MOD;
    tans = (1 + (tans + fly(n, cur - 1, 1, f - 1)) % MOD) % MOD;
  }
  if (dir == 1) {
    tans = (1 + (tans + fly(n, cur + 1, 0, f - 1)) % MOD) % MOD;
    tans = (tans + fly(n, cur - 1, 1, f)) % MOD;
  }
  memo[cur - 1][f - 1][dir] = tans;
  return tans;
}
long long int maximum(long long int n) {
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return n / i;
  }
  return 1;
}
vector<pair<long long int, long long int>> fact(long long int x) {
  vector<pair<long long int, long long int>> res;
  for (long long int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      int c = 0;
      while (x % i == 0) x /= i, c++;
      res.emplace_back(i, c);
    }
  }
  if (x > 1) res.emplace_back(x, 1);
  return res;
}
void solve() {
  long long int p, q, c, d, maxi = 0;
  cin >> p >> q;
  if (p % q) {
    cout << p;
    return;
  }
  vector<pair<long long int, long long int>> fq = fact(q);
  long long int ans = 1;
  for (auto i : fq) {
    int v = i.first;
    long long int temp = p;
    while (temp % v == 0) {
      temp /= v;
      if (temp % q != 0) {
        ans = max(ans, temp);
        break;
      }
    }
  }
  if (ans == -1) ans = p;
  cout << ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}

### Prompt

Please provide a cpp coded solution to the problem described below:

Oleg's favorite subjects are History and Math, and his favorite branch of mathematics is division.

To improve his division skills, Oleg came up with t pairs of integers p_i and q_i and for each pair decided to find the greatest integer x_i, such that: 

  * p_i is divisible by x_i; 
  * x_i is not divisible by q_i. 

Oleg is really good at division and managed to find all the answers quickly, how about you?

Input

The first line contains an integer t (1 ≤ t ≤ 50) — the number of pairs.

Each of the following t lines contains two integers p_i and q_i (1 ≤ p_i ≤ 10^{18}; 2 ≤ q_i ≤ 10^{9}) — the i-th pair of integers.

Output

Print t integers: the i-th integer is the largest x_i such that p_i is divisible by x_i, but x_i is not divisible by q_i.

One can show that there is always at least one value of x_i satisfying the divisibility conditions for the given constraints.

Example

Input


3
10 4
12 6
179 822


Output


10
4
179

Note

For the first pair, where p_1 = 10 and q_1 = 4, the answer is x_1 = 10, since it is the greatest divisor of 10 and 10 is not divisible by 4.

For the second pair, where p_2 = 12 and q_2 = 6, note that 

  * 12 is not a valid x_2, since 12 is divisible by q_2 = 6; 
  * 6 is not valid x_2 as well: 6 is also divisible by q_2 = 6. 

The next available divisor of p_2 = 12 is 4, which is the answer, since 4 is not divisible by 6.

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
using vi = vector<int>;
using vll = vector<long long int>;
using vd = vector<double>;
using vvi = vector<vi>;
int ctoi(char c) { return c - '0'; }
int slen(string s) { return s.length(); }
int vsize(vi a) { return (int)a.size(); }
int in() {
  int x;
  cin >> x;
  return x;
}
long long int n;
void kmin(long long int n, long long int m) {
  long long int val = n / m;
  n = n - (val * m);
  long long int val1 = (m - n) * (val - 1) * (val) / 2;
  long long int val2 = n * val * (val + 1) / 2;
  long long int val3 = val1 + val2;
  cout << val3 << " ";
}
void kmax(long long int n, long long int m) {
  n = n - (m - 1);
  long long int val = n * (n - 1) / 2;
  cout << val;
  cout << endl;
}
const int M = 1000000;
long long int prime(long long int x) {
  for (long long int i = 2; i * i <= x; i++) {
    if (x % i == 0) return i;
  }
  return x;
}
vector<pair<long long int, long long int>> v;
set<long long int> s;
bool check(long long int x) {
  for (int i = 1; i < n; i++) {
    if (v[i].first % x != 0 && v[i].second % x != 0) {
      return 0;
    }
  }
  return 1;
}
void get_prime(long long int x) {
  if (x % 2 == 0) s.insert(2);
  while (x % 2 == 0) x = x / 2;
  for (int i = 3; i <= sqrt(x); i += 2) {
    if (x % i == 0) {
      s.insert(i);
      while (x % i == 0) x = x / i;
    }
  }
  if (x > 2) {
    s.insert(x);
  }
}
vll ar[1000000];
set<long long int> cycle;
vll path;
bool vis[1000000];
int isp(int x) {
  if (x < 2) return 0;
  for (int i = 2; i * i <= x; i++)
    if (x % i == 0) return 0;
  return 1;
}
void dfs(int n, int m, int x, int y, bool visited[105][105]) {
  if (x >= n || y >= m || x < 0 || y < 0 || visited[x][y]) return;
  visited[x][y] = true;
  cout << x + 1 << " " << y + 1 << "\n";
  for (int i = 0; i < n; i++) dfs(n, m, i, y, visited);
  for (int i = 0; i < m; i++) dfs(n, m, x, i, visited);
}
long long int MAXN = 3e5 + 7;
long long int sumofdigits(long long int n) {
  long long int result = 0;
  while (n > 0) {
    result += n % 10;
    n = n / 10;
  }
  return result;
}
long long int MOD = 1e9 + 7;
long long int memo[1010][1010][2];
long long int fly(long long int n, long long int cur, long long int dir,
                  long long int f) {
  if (f == 1 || cur == 0 || cur == n + 1) return 0;
  if (memo[cur - 1][f - 1][dir] != -1) {
    return memo[cur - 1][f - 1][dir - 1];
  }
  long long int tans = 0;
  if (dir == 0) {
    tans = (tans + fly(n, cur + 1, 0, f)) % MOD;
    tans = (1 + (tans + fly(n, cur - 1, 1, f - 1)) % MOD) % MOD;
  }
  if (dir == 1) {
    tans = (1 + (tans + fly(n, cur + 1, 0, f - 1)) % MOD) % MOD;
    tans = (tans + fly(n, cur - 1, 1, f)) % MOD;
  }
  memo[cur - 1][f - 1][dir] = tans;
  return tans;
}
long long int maximum(long long int n) {
  for (int i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) return n / i;
  }
  return 1;
}
vector<pair<long long int, long long int>> fact(long long int x) {
  vector<pair<long long int, long long int>> res;
  for (long long int i = 2; i * i <= x; i++) {
    if (x % i == 0) {
      int c = 0;
      while (x % i == 0) x /= i, c++;
      res.emplace_back(i, c);
    }
  }
  if (x > 1) res.emplace_back(x, 1);
  return res;
}
void solve() {
  long long int p, q, c, d, maxi = 0;
  cin >> p >> q;
  if (p % q) {
    cout << p;
    return;
  }
  vector<pair<long long int, long long int>> fq = fact(q);
  long long int ans = 1;
  for (auto i : fq) {
    int v = i.first;
    long long int temp = p;
    while (temp % v == 0) {
      temp /= v;
      if (temp % q != 0) {
        ans = max(ans, temp);
        break;
      }
    }
  }
  if (ans == -1) ans = p;
  cout << ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
    cout << "\n";
  }
  return 0;
}

```