#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;
}
