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.
/**
 * @author vivek
 * programming is thinking, not typing
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class C {

    public static HashMap<Long, Integer> primeFactors(long n) {

        HashMap<Long, Integer> ans = new HashMap<>();

        // Print the number of 2s that divide n
        while (n % 2 == 0) {
            ans.putIfAbsent(2L, 0);
            ans.put(2L, ans.get(2L) + 1);
            n /= 2;
        }

        // n must be odd at this point.  So we can
        // skip one element (Note i = i +2)
        for (long i = 3; i <= Math.sqrt(n); i += 2) {
            // While i divides n, print i and divide n
            while (n % i == 0) {
                ans.putIfAbsent(i, 0);
                ans.put(i, ans.get(i) + 1);
                n /= i;
            }
        }

        // This condition is to handle the case whien
        // n is a prime number greater than 2
        if (n > 2) {
            ans.putIfAbsent(n, 0);
            ans.put(n, ans.get(n) + 1);
        }

        return ans;
    }

    private static void solveTC(int __) {

        /* For Google */
//		ans.append("Case #").append(__).append(": ");

        //code start

        long p = scn.nextLong(), q = scn.nextLong();
        if (p % q != 0) {
            print(p);
        } else {

            long min = Long.MAX_VALUE;

            HashMap<Long, Integer> map = primeFactors(q);

            for (long key : map.keySet()) {
                long temp = p;
                int count = 0;
                while (temp % key == 0) {
                    count++;
                    temp /= key;
                }
                int rem = count - map.get(key) + 1;
                min = Math.min(min, pow(key, rem));
            }

            print(p / min);

        }

        //code end

        print("\n");
    }

    public static long pow(long n, int p) {

        if (p == 0) {
            return 1L;
        }

        long a = pow(n, p / 2);

        if (p % 2 == 0) {
            return a * a;
        } else {
            return a * a * n;
        }
    }

    /**
     * Don't copy other's templates, make your own <br>
     * It would be much more beneficial
     */

    public static void main(String[] args) {
        scn = new Scanner();
        ans = new StringBuilder();
        int t = scn.nextInt();
//		int t = 1;

//        int limit=               ;
//        sieve(limit);

        /*
        try {
            System.setOut(new PrintStream(new File("file_i_o\\output.txt")));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
*/
        for (int i = 1; i <= t; i++) {
            solveTC(i);
        }
        System.out.print(ans);
    }
    //Stuff for prime start

    /**
     * List containing prime numbers <br>
     * <b>i<sup>th</sup></b> position contains <b>i<sup>th</sup></b> prime number <br>
     * 0th index is <b>null</b>
     */
    private static ArrayList<Integer> listOfPrimes;

    /**
     * query <b>i<sup>th</sup></b> element to get if its prime of not
     */
    private static boolean[] isPrime;

    /**
     * Performs Sieve of Erathosnesis and initialise isPrime array and listOfPrimes list
     *
     * @param limit the number till which sieve is to be performed
     */
    private static void sieve(int limit) {
        listOfPrimes = new ArrayList<>();
        listOfPrimes.add(null);
        boolean[] array = new boolean[limit + 1];

        Arrays.fill(array, true);
        array[0] = false;
        array[1] = false;

        for (int i = 2; i <= limit; i++) {
            if (array[i]) {
                for (int j = i * i; j <= limit; j += i) {
                    array[j] = false;
                }
            }
        }
        isPrime = array;
        for (int i = 0; i <= limit; i++) {
            if (array[i]) {
                listOfPrimes.add(i);
            }
        }
    }
    //stuff for prime end

    /**
     * Calculates the Least Common Multiple of two numbers
     *
     * @param a First number
     * @param b Second Number
     * @return Least Common Multiple of <b>a</b> and <b>b</b>
     */
    private static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    /**
     * Calculates the Greatest Common Divisor of two numbers
     *
     * @param a First number
     * @param b Second Number
     * @return Greatest Common Divisor of <b>a</b> and <b>b</b>
     */
    private static long gcd(long a, long b) {
        return (b == 0) ? a : gcd(b, a % b);
    }

    static void print(Object obj) {
        ans.append(obj.toString());
    }


    static Scanner scn;
    static StringBuilder ans;

    //Fast Scanner
    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

        public Scanner() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
/*
            try {
                br = new BufferedReader(new
                        InputStreamReader(new FileInputStream(new File("file_i_o\\input.txt"))));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
*/
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        Integer[] nextIntegerArray(int n) {
            Integer[] array = new Integer[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextInt();
            }
            return array;
        }

        long[] nextLongArray(int n) {
            long[] array = new long[n];
            for (int i = 0; i < n; i++) {
                array[i] = nextLong();
            }
            return array;
        }

        String[] nextStringArray() {
            return nextLine().split(" ");
        }

        String[] nextStringArray(int n) {
            String[] array = new String[n];
            for (int i = 0; i < n; i++) {
                array[i] = next();
            }
            return array;
        }
    }
}
