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 CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
map<long long, int> m;
map<long long, int>::iterator it;
const int times = 7;
int number = 0;
int n, low, high, mid, prime[100000], cnt_p, mi[100000], list[2][111111],
    cnt_list[2], pos[110000];
long long a[110000], xx, yy, ds;
bool is[110000];
int ex[111111];
long long gcd(long long a, long long b) {
  long long tmp;
  while (b) {
    tmp = a % b;
    a = b;
    b = tmp;
  }
  return a;
}
void ex_gcd(long long a, long long n) {
  if (n == 0) {
    xx = 1;
    yy = 0;
    ds = a;
    return;
  }
  ex_gcd(n, a % n);
  long long tmp;
  tmp = xx;
  xx = yy;
  yy = tmp - (a / n) * yy;
}
const int S = 20;
long long mult_mod(long long a, long long b, long long c) {
  a %= c;
  b %= c;
  long long ret = 0;
  while (b) {
    if (b & 1) {
      ret += a;
      ret %= c;
    }
    a <<= 1;
    if (a >= c) a %= c;
    b >>= 1;
  }
  return ret;
}
long long mult(long long a, long long n, long long mod) {
  if (n == 0) return 0;
  long long ret = mult(a, n / 2, mod);
  ret = (ret + ret) % mod;
  if (n % 2) ret = (ret + a) % mod;
  return ret;
}
long long pow_mod(long long x, long long n, long long mod) {
  if (n == 1) return x % mod;
  x %= mod;
  long long tmp = x;
  long long ret = 1;
  while (n) {
    if (n & 1) ret = mult_mod(ret, tmp, mod);
    tmp = mult_mod(tmp, tmp, mod);
    n >>= 1;
  }
  return ret;
}
bool check(long long a, long long n, long long x, long long t) {
  long long ret = pow_mod(a, x, n);
  long long last = ret;
  for (int i = 1; i <= t; i++) {
    ret = mult_mod(ret, ret, n);
    if (ret == 1 && last != 1 && last != n - 1) return true;
    last = ret;
  }
  if (ret != 1) return true;
  return false;
}
bool Miller_Rabin(long long n) {
  if (n < 2) return false;
  if (n == 2) return true;
  if ((n & 1) == 0) return false;
  long long x = n - 1;
  long long t = 0;
  while ((x & 1) == 0) {
    x >>= 1;
    t++;
  }
  for (int i = 0; i < S; i++) {
    long long a = rand() % (n - 1) + 1;
    if (check(a, n, x, t)) return false;
  }
  return true;
}
long long factor[100];
int tol, cnt;
long long Pollard_rho(long long x, long long c) {
  long long i = 1, k = 2;
  long long x0 = rand() % x;
  long long y = x0;
  while (1) {
    i++;
    x0 = (mult_mod(x0, x0, x) + c) % x;
    long long d = gcd(abs(y - x0), x);
    if (d != 1 && d != x) return d;
    if (y == x0) return x;
    if (i == k) {
      y = x0;
      k += k;
    }
  }
}
void findfac(long long n) {
  if (n == 1) return;
  if (Miller_Rabin(n)) {
    m[n]++;
    return;
  }
  long long p = n;
  while (p >= n) p = Pollard_rho(p, rand() % (n - 1) + 1);
  findfac(p);
  findfac(n / p);
}
struct query {
  long long n, k;
  int id;
  bool operator<(const query &temp) const { return k < temp.k; }
};
query qy[11111];
long long k_list[11111], dist[32333333];
bool ans[11111];
int cnt_k;
struct pp {
  long long vl;
  int id;
  bool operator<(const pp &temp) const {
    if (vl == temp.vl) return id < temp.id;
    return vl < temp.vl;
  }
};
map<pp, int> hs;
map<pp, int>::iterator ht;
pp now, u;
long long power(long long a, long long n, long long mod) {
  if (n == 0) return 1;
  long long ret = power(a, n / 2, mod);
  ret = ret * ret % mod;
  if (n % 2) ret = ret * a % mod;
  return ret;
}
int main() {
  int i, j, s, p, q, t;
  scanf("%d", &t);
  for (i = 0; i < t; i++) {
    scanf("%lld%lld", &qy[i].n, &qy[i].k);
    qy[i].id = i;
  }
  sort(qy, qy + t);
  for (i = 0; i < t;) {
    for (j = i; j < t; j++) {
      if (qy[i].k != qy[j].k) break;
    }
    m.clear();
    findfac(qy[i].k);
    cnt = 0;
    for (it = m.begin(); it != m.end(); it++) factor[cnt++] = it->first;
    if (cnt == 2) {
      for (s = i; s < j; s++) {
        long long vl = qy[s].n % factor[0], x = factor[1] % factor[0];
        vl = vl * power(x, factor[0] - 2, factor[0]) % factor[0];
        if (factor[1] * vl <= qy[s].n)
          ans[qy[s].id] = 1;
        else
          ans[qy[s].id] = 0;
      }
    } else if (cnt > 2) {
      for (s = 0; s < factor[0]; s++) dist[s] = 1e18 + 9;
      dist[0] = 0;
      hs.clear();
      now.id = 0;
      now.vl = 0;
      hs[now];
      while (hs.size()) {
        ht = hs.begin();
        u = ht->first;
        hs.erase(u);
        if (u.vl > dist[u.id]) continue;
        for (s = 1; s < cnt; s++) {
          int id = (u.id + factor[s]) % factor[0];
          long long vl = dist[u.id] + factor[s];
          if (dist[id] > vl) {
            dist[id] = vl;
            now.id = id;
            now.vl = vl;
            hs[now];
          }
        }
      }
      for (s = i; s < j; s++) {
        if (dist[qy[s].n % factor[0]] <= qy[s].n)
          ans[qy[s].id] = 1;
        else
          ans[qy[s].id] = 0;
      }
    } else {
      for (s = i; s < j; s++) ans[qy[s].id] = qy[s].n % factor[0] == 0;
    }
    i = j;
  }
  for (i = 0; i < t; i++) {
    if (ans[i])
      puts("YES");
    else
      puts("NO");
  }
  return 0;
}