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;
template <typename TP>
inline void read(TP &ret) {
  TP x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  ret = (TP)x * f;
}
int t;
struct node {
  long long n, k;
  int id;
  bool operator<(const node &other) const { return k < other.k; }
} a[10010];
long long bas[5] = {2, 3, 7, 61, 24251};
long long gcd(long long x, long long y) {
  if (!y) {
    return x;
  }
  return gcd(y, x % y);
}
long long add(long long a, long long b, long long mod) {
  return (a + b > mod) ? a + b - mod : a + b;
}
long long ksc(long long a, long long b, long long mod) {
  long long sum = 0;
  while (b) {
    if (b & 1) {
      sum = add(sum, a, mod);
      b--;
    }
    a = add(a, a, mod);
    b >>= 1;
  }
  return sum % mod;
}
long long ksm(long long a, long long b, long long mod) {
  long long product = 1;
  while (b) {
    if (b & 1) {
      product = ksc(product, a, mod);
      b--;
    }
    a = ksc(a, a, mod);
    b >>= 1;
  }
  return product % mod;
}
bool Miller_Rabin(long long x, long long b) {
  if (ksm(b, x - 1, x) != 1) return 0;
  long long k = x - 1;
  while (!(k & 1)) {
    k >>= 1;
    long long d = ksm(b, k, x);
    if (d != 1 && d != x - 1) return 0;
    if (d == x - 1) return 1;
  }
  return 1;
}
bool Miller_Rabin(long long x) {
  if (x < 2 || x == 46856248255981) return 0;
  for (int i = 0; i < 5; i++) {
    if (x == bas[i]) return 1;
  }
  for (int i = 0; i < 5; i++) {
    if (!Miller_Rabin(x, bas[i])) return 0;
  }
  return 1;
}
long long Mandelbrot(long long x, long long c, long long p) {
  return (ksc(x, x, p) + c) % p;
}
long long Pollard_Rho(long long x) {
  long long s, t, c = 1ll * rand() % (x - 1) + 1;
  s = t = 0;
  long long val = 1;
  int goal = 1;
  for (;; goal <<= 1, s = t, val = 1) {
    for (int i = 1; i <= goal; i++) {
      t = Mandelbrot(t, c, x);
      val = ksc(val, abs(t - s), x);
      if (!(i % 127)) {
        long long g = gcd(val, x);
        if (g > 1) return g;
      }
    }
    long long g = gcd(val, x);
    if (g > 1) return g;
  }
}
vector<long long> fac;
long long min_factor;
void divide(long long x) {
  if (x < 2) {
    return;
  }
  if (Miller_Rabin(x)) {
    min_factor = min(min_factor, x);
    fac.push_back(x);
    return;
  }
  long long p = x;
  while (p >= x) p = Pollard_Rho(x);
  while (!(x % p)) {
    x /= p;
  }
  divide(x);
  divide(p);
}
long long exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = exgcd(b, a % b, x, y);
  long long res = x;
  x = y;
  y = res - a / b * y;
  return d;
}
long long dis[200020];
bool vis[200020];
queue<int> q;
void spfa(long long mod) {
  for (int i = 0; i < mod; i++) {
    dis[i] = 1000000000000000000ll;
    vis[i] = 0;
  }
  dis[0] = 0;
  q.push(0);
  vis[0] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    vis[u] = 0;
    for (int i = 1; i < fac.size(); i++) {
      int v = (u + fac[i]) % mod;
      if (dis[v] > dis[u] + fac[i]) {
        dis[v] = dis[u] + fac[i];
        if (!vis[v]) {
          q.push(v);
          vis[v] = 1;
        }
      }
    }
  }
}
bool ans[10010];
int main() {
  srand(time(NULL));
  read(t);
  for (int i = 1; i <= t; i++) {
    read(a[i].n), read(a[i].k);
    a[i].id = i;
  }
  sort(a + 1, a + t + 1);
  for (int i = 1; i <= t; i++) {
    int now = i;
    while (now < t && a[now + 1].k == a[i].k) now++;
    if (a[i].k == 1) {
      i = now;
      continue;
    }
    fac.clear();
    min_factor = 1000000000000000000ll;
    divide(a[i].k);
    sort(fac.begin(), fac.end());
    if (fac.size() == 1) {
      for (int j = i; j <= now; j++) {
        if (!(a[j].n % fac[0])) ans[a[j].id] = 1;
      }
      i = now;
      continue;
    }
    if (fac.size() == 2) {
      long long x, y;
      long long g = exgcd(fac[0], fac[1], x, y);
      long long b = fac[1] / g;
      x = add(x, b, b);
      for (int j = i; j <= now; j++) {
        if (!(a[j].n % g)) {
          long long dx = x, dy = y;
          dx = ksc(dx, a[j].n / g, b);
          dy = (a[j].n - fac[0] * dx) / fac[1];
          if (dy >= 0) ans[a[j].id] = 1;
        }
      }
      i = now;
      continue;
    }
    spfa(min_factor);
    for (int j = i; j <= now; j++) {
      if (dis[a[j].n % min_factor] <= a[j].n) ans[a[j].id] = 1;
    }
    i = now;
  }
  for (int i = 1; i <= t; i++) {
    printf("%s\n", ans[i] ? "YES" : "NO");
  }
}