#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
long long gcd(long long x, long long y) {
  if (x == 0) return y;
  return gcd(y % x, x);
}
long long qpow(long long x, long long y) {
  long long ans = 1;
  while (y) {
    if (y & 1) ans = ans * x % mod;
    x = x * x % mod, y >>= 1;
  }
  return ans;
}
int T, cnt, now[110];
long long u, v, d, p[110], frac[110], inv[110];
int C(int x, int y) { return frac[x] * inv[y] % mod * inv[x - y] % mod; }
long long solve(long long x) {
  int res = 0, tot = 0;
  long long ans = 1;
  for (int i = 1; i <= cnt; i++) {
    if (x % p[i] == 0) now[++tot] = 0;
    while (x % p[i] == 0) x /= p[i], now[tot]++, res++;
  }
  for (int i = 1; i <= tot; i++) {
    ans = ans * C(res, now[i]) % mod;
    res -= now[i];
  }
  return ans;
}
int main() {
  frac[0] = inv[0] = 1;
  for (int i = 1; i <= 100; i++) frac[i] = frac[i - 1] * i % mod;
  for (int i = 1; i <= 100; i++) inv[i] = qpow(frac[i], mod - 2);
  scanf("%lld%d", &d, &T);
  for (long long i = 2; i * i <= d; i++) {
    if (d % i == 0) p[++cnt] = i;
    while (d % i == 0) d /= i;
  }
  if (d > 1) p[++cnt] = d;
  while (T--) {
    scanf("%lld%lld", &u, &v);
    long long g = gcd(u, v);
    u /= g, v /= g;
    printf("%lld\n", solve(u) * solve(v) % mod);
  }
}
