Problem: Surely you have seen insane videos by South Korean rapper PSY, such as "Gangnam Style", "Gentleman" and "Daddy". You might also hear that PSY has been recording video "Oppa Funcan Style" two years ago (unfortunately we couldn't find it on the internet). We will remind you what this hit looked like (you can find original description [here](http://acm.timus.ru/problem.aspx?space=1&num=2107&locale=en)):

On the ground there are n platforms, which are numbered with integers from 1 to n, on i-th platform there is a dancer with number i. Further, every second all the dancers standing on the platform with number i jump to the platform with the number f(i). The moving rule f is selected in advance and is not changed throughout the clip.

The duration of the clip was k seconds and the rule f was chosen in such a way that after k seconds all dancers were in their initial positions (i.e. the i-th dancer stood on the platform with the number i). That allowed to loop the clip and collect even more likes.

PSY knows that enhanced versions of old artworks become more and more popular every day. So he decided to release a remastered-version of his video.

In his case "enhanced version" means even more insanity, so the number of platforms can be up to 10^{18}! But the video director said that if some dancer stays on the same platform all the time, then the viewer will get bored and will turn off the video immediately. Therefore, for all x from 1 to n f(x) ≠ x must hold.

Big part of classic video's success was in that looping, so in the remastered version all dancers should return to their initial positions in the end of the clip as well.

PSY hasn't decided on the exact number of platforms and video duration yet, so he asks you to check if there is a good rule f for different options.

Input

In the first line of input there is one integer t (1 ≤ t ≤ 10^{4}) — the number of options for n and k to check.

In the next t lines the options are given: each option is described with two integers n and k (1 ≤ n ≤ 10^{18}, 1 ≤ k ≤ 10^{15}) — the number of dancers and the duration in seconds.

It is guaranteed that the number of different values of k in one test is not greater than 50.

Output

Print t lines. If the i-th option of the video is feasible, print "YES" (without quotes) in i-th line, otherwise print "NO" (without quotes).

Example

Input

3
7 7
3 8
5 6


Output

YES
NO
YES

Solution (in JAVA):

Solution:
//package com.company;

import javafx.util.Pair;

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
    static long TIME_START, TIME_END;
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
//        Scanner sc = new Scanner(new FileInputStream("Test.in"));
        PrintWriter pw = new PrintWriter(System.out);
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.out"));
//        PrintWriter pw = new PrintWriter(new FileOutputStream("Test.in"));
//        Task tt = new Task();
//        tt.generate(22, 1000000, pw);
//        pw.close();
//        pw = new PrintWriter(new FileOutputStream("Test.out"));
        Runtime runtime = Runtime.getRuntime();
        long usedMemoryBefore = runtime.totalMemory() - runtime.freeMemory();
        TIME_START = System.currentTimeMillis();
        Task t = new Task();
        t.solve(sc, pw);
        TIME_END = System.currentTimeMillis();
        long usedMemoryAfter = runtime.totalMemory() - runtime.freeMemory();
        pw.close();
//        System.out.println("Memory increased:" + (usedMemoryAfter-usedMemoryBefore) / 1000000 );
//        System.out.println("Time used: " + (TIME_END - TIME_START) + ".");
    }

    public static class Task {
        int M = 31622800;
        int P = 1952000;
        int[] factors;
        int[] primes;
        void sieve() {
            factors = new int[M];
            Arrays.fill(factors, -1);
            int cnt = 0;
            primes = new int[P];
            for (int i = 2; i < M; i++) {
                if (factors[i] == -1) {
                    factors[i] = cnt;
                    primes[cnt++] = i;
                }
                for (int j = 0; j < cnt; j++) {
                    int pr = primes[j];
                    if (pr * i >= M) break;
                    factors[pr * i] = j;
                    if (i % pr == 0) break;
                }
            }
            P = cnt;
        }

        List<Long> factorize(long x) {
            List<Long> res = new ArrayList<>();
            for (int i = 0; i < P; i++) {
                if (x % primes[i] == 0) {
                    res.add((long) primes[i]);
                    while (x % primes[i] == 0) {
                        x /= primes[i];
                    }
                }
                if (x == 1) break;
            }
            if (x != 1) res.add(x);
            return res;
        }

        public static long[] xgcd(long a, long b){
            long[] retvals={0,0,0};
            long aa[]={1,0}, bb[]={0,1}, q=0;
            while(true) {
                q = a / b; a = a % b;
                aa[0] = aa[0] - q*aa[1];  bb[0] = bb[0] - q*bb[1];
                if (a == 0) {
                    retvals[0] = b; retvals[1] = aa[1]; retvals[2] = bb[1];
                    return retvals;
                };
                q = b / a; b = b % a;
                aa[1] = aa[1] - q*aa[0];  bb[1] = bb[1] - q*bb[0];
                if (b == 0) {
                    retvals[0] = a; retvals[1] = aa[0]; retvals[2] = bb[0];
                    return retvals;
                };
            }
        }

        public BigInteger ceildiv(BigInteger a, BigInteger b) {
            BigInteger[] dr = a.multiply(BigInteger.valueOf(-1)).divideAndRemainder(b);
            if (dr[1].compareTo(BigInteger.ZERO) == 0) {
                return dr[0];
            } else {
                return dr[0].add(BigInteger.ONE);
            }
        }

        public boolean solve2(long x, long y, long z) {
            long[] xgc = xgcd(x, y);
            if (z % xgc[0] != 0) return false;
            long amplif = z / xgc[0];
            BigInteger x1 = BigInteger.valueOf(y / xgc[0]);
            BigInteger y1 = BigInteger.valueOf(x / xgc[0]);
            BigInteger x0 = BigInteger.valueOf(xgc[1]).multiply(BigInteger.valueOf(amplif));
            BigInteger y0 = BigInteger.valueOf(xgc[2]).multiply(BigInteger.valueOf(amplif));

            xgc[1] *= amplif;
            xgc[2] *= amplif;

            if (x0.compareTo(BigInteger.ZERO) < 0) {
                BigInteger div = ceildiv(x0, x1);
                return y0.subtract(div.multiply(y1)).compareTo(BigInteger.ZERO) >= 0;
            } else if (y0.compareTo(BigInteger.ZERO) < 0) {
                BigInteger div = ceildiv(y0, y1);
                return x0.subtract(div.multiply(x1)).compareTo(BigInteger.ZERO) >= 0;
            }
            return true;
        }

        public boolean solve1(long x, long z) {
            if (x == 1) return false;
            return z % x == 0;
        }

        public boolean solve3(int idx, long z) {
            ModGraph graph = mg.get(idx);
            int mod = (int) (z % Ks.get(idx).get(0));
            return graph.dist[mod] <= z;
        }

        // edge x --> y iff x + num[i] === y mod num[0]
        public class ModGraph {
            List<Long> nums;
            long[] dist;
            public ModGraph(List<Long> list) {
                nums = list;
                int l = Math.toIntExact(list.get(0));
                dist = new long[l];
            }
            public void dijkstra() {
                PriorityQueue<Pair<Integer, Long>> pq = new PriorityQueue<>(new Comparator<Pair<Integer, Long>>() {
                    @Override
                    public int compare(Pair<Integer, Long> p1, Pair<Integer, Long> p2) {
                        return Long.compare(p1.getValue(), p2.getValue());
                    }
                });

                Arrays.fill(dist, Long.MAX_VALUE / 2);
                pq.offer(new Pair<>(0, 0L));
                while (!pq.isEmpty()) {
                    Pair<Integer, Long> next = pq.poll();
                    int u = next.getKey();
                    long du = next.getValue();
                    if (dist[u] > du) {
                        dist[u] = du;
                        for (int i = 1; i < nums.size(); i++) {
                            int v = (int) ((nums.get(i) + u) % nums.get(0));
                            long dv = nums.get(i) + du;
                            if (dist[v] > dv) {
                                pq.offer(new Pair<>(v, dv));
                            }
                        }
                    }
                }
            }
        }
        List<ModGraph> mg;
        List<List<Long>> Ks;
        Map<Long, Integer> kMap;
        int t;
        long[] A;
        long[] B;
        public String solve(boolean t) {
            return t ? "YES" : "NO";
        }
        public void solve(Scanner sc, PrintWriter pw) throws IOException {
            sieve();
            t = sc.nextInt();
            A = new long[t];
            B = new long[t];
            Ks = new ArrayList<>();
            kMap = new HashMap<>();
            mg = new ArrayList<>();
            for (int i = 0; i < t; i++) {
                long a = sc.nextLong();
                long b = sc.nextLong();
                A[i] = a;
                B[i] = b;
                if (kMap.containsKey(b)) {
                    continue;
                } else {
                    kMap.put(b, Ks.size());
                    List<Long> add = factorize(b);
                    Ks.add(add);
                    if (add.size() >= 3) {
                        ModGraph graph = new ModGraph(add);
                        graph.dijkstra();
                        mg.add(graph);
                    } else {
                        mg.add(null);
                    }
                }
            }
            for (int i = 0; i < t; i++) {
                long a = A[i];
                long b = B[i];
                int idx = kMap.get(b);
                if (Ks.get(idx).size() <= 1) {
                    pw.println(solve(solve1(b, a)));
                } else if (Ks.get(idx).size() == 2) {
                    pw.println(solve(solve2(Ks.get(idx).get(0), Ks.get(idx).get(1), a)));
                } else {
                    pw.println(solve(solve3(idx, a)));
                }
            }

        }
    }


    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

        public Scanner(FileReader s) throws FileNotFoundException {br = new BufferedReader(s);}

        public String next() throws IOException
        {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {return br.readLine();}

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

        public boolean ready() throws IOException {return br.ready();}
    }
}