#include <bits/stdc++.h>
using namespace std;
const long long P = 998244353, MAXN = 1010;
long long d, q, a, b, g, tot, fac[MAXN], inv[MAXN], pri[MAXN];
vector<long long> v;
long long gcd(long long a, long long b) { return (b ? gcd(b, a % b) : a); }
long long qpow(long long a, long long b) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (res * a) % P;
    }
    a = (a * a) % P, b >>= 1;
  }
  return res;
}
long long solve(long long x) {
  long long res = 1, sum = 0;
  for (int i = 1; i <= tot; i++) {
    long long cnt = 0;
    while (x % pri[i] == 0) {
      cnt++, x /= pri[i];
    }
    res = (1ll * res * inv[cnt]) % P;
    sum += cnt;
  }
  res = (1ll * res * fac[sum]) % P;
  return res;
}
int main() {
  scanf("%lld%lld", &d, &q);
  for (long long i = 2; i * i <= d; i++) {
    if (!(d % i)) {
      while (d % i == 0) {
        d /= i;
      }
      pri[++tot] = i;
    }
  }
  if (d > 1) {
    pri[++tot] = d;
  }
  fac[0] = inv[0] = 1;
  for (int i = 1; i <= 1000; i++) {
    fac[i] = (1ll * fac[i - 1] * i) % P;
  }
  inv[1000] = qpow(fac[1000], P - 2);
  for (int i = 999; i >= 1; i--) {
    inv[i] = (1ll * inv[i + 1] * (i + 1)) % P;
  }
  for (int i = 1; i <= q; i++) {
    scanf("%lld%lld", &a, &b);
    g = gcd(a, b);
    a /= g, b /= g;
    printf("%lld\n", (1ll * solve(a) * solve(b)) % P);
  }
  return 0;
}
