#include <bits/stdc++.h>
using namespace std;
long long int mod = 1000000007;
long long int Comb(long long int n, long long int k) {
  long double res = 1;
  for (long long int i = 1; i <= k; ++i) res = res * (n - k + i) / i;
  return (long long int)(res + 0.01);
}
long long int Abs(long long int x) {
  if (x >= 0) return x;
  return (-1) * x;
}
long double Absd(long double x) {
  if (x >= 0) return x;
  return (-1) * x;
}
long long int Pow(long long int n, long long int k) {
  if (k == 1) return (n % mod);
  if (k == 0) return 1;
  long long int x = Pow(n, k / 2);
  if (k % 2) return (((x * x) % mod) * n) % mod;
  return ((x * x) % mod);
}
int Max(int a, int b) { return (a > b) ? a : b; }
int Min(int a, int b) { return (a < b) ? a : b; }
struct Node {
  int parent;
  char c;
  int child[2];
  Node() {
    parent = -1;
    child[0] = -1;
    child[1] = -1;
  }
};
int lowerIndex(int arr[], int l, int h, int x) {
  while (l <= h) {
    int mid = (l + h) / 2;
    if (arr[mid] >= x)
      h = mid - 1;
    else
      l = mid + 1;
  }
  return l;
}
int upperIndex(int arr[], int l, int h, int y) {
  while (l <= h) {
    int mid = (l + h) / 2;
    if (arr[mid] <= y)
      l = mid + 1;
    else
      h = mid - 1;
  }
  return h;
}
int countInRange(int arr[], int l, int h, int x, int y) {
  int count = 0;
  count = upperIndex(arr, l, h, y) - lowerIndex(arr, l, h, x) + 1;
  return count;
}
int printPrimeFactors(int n) {
  int k = 0;
  while (n % 2 == 0) {
    k++;
    n = n / 2;
  }
  for (int i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      k++;
      n = n / i;
    }
  }
  if (n > 2) k++;
  return k;
}
bool ispalindrome(string s) {
  string s1 = s;
  reverse(s1.begin(), s1.end());
  if (s == s1) return 1;
  return 0;
}
void dfs(vector<vector<int> > &graph, vector<bool> &visited, int i) {
  visited[i] = 1;
  for (auto j : graph[i]) {
    if (visited[j]) return;
    dfs(graph, visited, j);
  }
  return;
}
bool cust(long double a, long double b) { return (Absd(a) < Absd(b)); }
string make_string(string s, int n, int k) {
  string s1(k, ' ');
  for (int i = 0; i < k; i++) {
    s1[i] = s[i % n];
  }
  return s1;
}
bool isprime(long long int n) {
  if ((n == 2) || (n == 3)) return 1;
  for (long long int i = 2; (i * i) <= n; i++) {
    if ((n % i) == 0) {
      return 0;
    }
  }
  return 1;
}
long long int find_sqrt(long long int k, long long int d) {
  long long int low = 0, high = (d / k) + 1, sq = (d * d), ans;
  long long int mid;
  while (low <= high) {
    mid = (low + high) / 2;
    long long int x = k * mid;
    if ((2 * x * x) == sq) return mid;
    if ((2 * x * x) < sq) {
      low = (mid + 1);
      ans = mid;
    } else
      high = (mid - 1);
  }
  return mid;
}
long long int floorSqrt(long long int x) {
  if (x == 0 || x == 1) return x;
  long long int start = 1, end = x, ans;
  while (start <= end) {
    long long int mid = (start + end) / 2;
    if (mid * mid == x) return mid;
    if (mid <= x / mid) {
      start = mid + 1;
      ans = mid;
    } else
      end = mid - 1;
  }
  return ans;
}
long long int findp(long long int r, long long int s, long long int p,
                    long long int q) {
  long long int x = 1;
  while (r % q == 0) r /= s;
  x = max(x, r);
  return x;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    long long int p, q;
    cin >> p >> q;
    long long int x = -1;
    if (q > p)
      x = p;
    else if (p % q)
      x = p;
    else {
      long long int r = p, s = q;
      x = 1;
      for (long long int i = 2; i <= floorSqrt(s); i++) {
        while (s % i == 0) {
          s /= i;
          x = max(x, findp(r, i, p, q));
        }
      }
      if (s > 1) x = max(x, findp(r, s, p, q));
    }
    cout << x << '\n';
  }
}

### Prompt

Please formulate a Cpp solution to the following problem:

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;
long long int mod = 1000000007;
long long int Comb(long long int n, long long int k) {
  long double res = 1;
  for (long long int i = 1; i <= k; ++i) res = res * (n - k + i) / i;
  return (long long int)(res + 0.01);
}
long long int Abs(long long int x) {
  if (x >= 0) return x;
  return (-1) * x;
}
long double Absd(long double x) {
  if (x >= 0) return x;
  return (-1) * x;
}
long long int Pow(long long int n, long long int k) {
  if (k == 1) return (n % mod);
  if (k == 0) return 1;
  long long int x = Pow(n, k / 2);
  if (k % 2) return (((x * x) % mod) * n) % mod;
  return ((x * x) % mod);
}
int Max(int a, int b) { return (a > b) ? a : b; }
int Min(int a, int b) { return (a < b) ? a : b; }
struct Node {
  int parent;
  char c;
  int child[2];
  Node() {
    parent = -1;
    child[0] = -1;
    child[1] = -1;
  }
};
int lowerIndex(int arr[], int l, int h, int x) {
  while (l <= h) {
    int mid = (l + h) / 2;
    if (arr[mid] >= x)
      h = mid - 1;
    else
      l = mid + 1;
  }
  return l;
}
int upperIndex(int arr[], int l, int h, int y) {
  while (l <= h) {
    int mid = (l + h) / 2;
    if (arr[mid] <= y)
      l = mid + 1;
    else
      h = mid - 1;
  }
  return h;
}
int countInRange(int arr[], int l, int h, int x, int y) {
  int count = 0;
  count = upperIndex(arr, l, h, y) - lowerIndex(arr, l, h, x) + 1;
  return count;
}
int printPrimeFactors(int n) {
  int k = 0;
  while (n % 2 == 0) {
    k++;
    n = n / 2;
  }
  for (int i = 3; i <= sqrt(n); i = i + 2) {
    while (n % i == 0) {
      k++;
      n = n / i;
    }
  }
  if (n > 2) k++;
  return k;
}
bool ispalindrome(string s) {
  string s1 = s;
  reverse(s1.begin(), s1.end());
  if (s == s1) return 1;
  return 0;
}
void dfs(vector<vector<int> > &graph, vector<bool> &visited, int i) {
  visited[i] = 1;
  for (auto j : graph[i]) {
    if (visited[j]) return;
    dfs(graph, visited, j);
  }
  return;
}
bool cust(long double a, long double b) { return (Absd(a) < Absd(b)); }
string make_string(string s, int n, int k) {
  string s1(k, ' ');
  for (int i = 0; i < k; i++) {
    s1[i] = s[i % n];
  }
  return s1;
}
bool isprime(long long int n) {
  if ((n == 2) || (n == 3)) return 1;
  for (long long int i = 2; (i * i) <= n; i++) {
    if ((n % i) == 0) {
      return 0;
    }
  }
  return 1;
}
long long int find_sqrt(long long int k, long long int d) {
  long long int low = 0, high = (d / k) + 1, sq = (d * d), ans;
  long long int mid;
  while (low <= high) {
    mid = (low + high) / 2;
    long long int x = k * mid;
    if ((2 * x * x) == sq) return mid;
    if ((2 * x * x) < sq) {
      low = (mid + 1);
      ans = mid;
    } else
      high = (mid - 1);
  }
  return mid;
}
long long int floorSqrt(long long int x) {
  if (x == 0 || x == 1) return x;
  long long int start = 1, end = x, ans;
  while (start <= end) {
    long long int mid = (start + end) / 2;
    if (mid * mid == x) return mid;
    if (mid <= x / mid) {
      start = mid + 1;
      ans = mid;
    } else
      end = mid - 1;
  }
  return ans;
}
long long int findp(long long int r, long long int s, long long int p,
                    long long int q) {
  long long int x = 1;
  while (r % q == 0) r /= s;
  x = max(x, r);
  return x;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    long long int p, q;
    cin >> p >> q;
    long long int x = -1;
    if (q > p)
      x = p;
    else if (p % q)
      x = p;
    else {
      long long int r = p, s = q;
      x = 1;
      for (long long int i = 2; i <= floorSqrt(s); i++) {
        while (s % i == 0) {
          s /= i;
          x = max(x, findp(r, i, p, q));
        }
      }
      if (s > 1) x = max(x, findp(r, s, p, q));
    }
    cout << x << '\n';
  }
}

```