#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
const int INF = 0x3f3f3f3f;
long long inv[maxn], p[maxn], s[maxn];
long long C(long long n, long long m) {
  return p[n] * inv[m] % 998244353 * inv[n - m] % 998244353;
}
int main() {
  long long t;
  t = 1;
  while (t--) {
    long long d, cnt = 0;
    scanf("%lld", &d);
    for (long long i = 2; i * i <= d; i++) {
      if (d % i == 0) s[++cnt] = i;
      while (d % i == 0) d /= i;
    }
    if (d != 1ll) s[++cnt] = d;
    inv[0] = inv[1] = p[0] = p[1] = 1ll;
    for (long long i = 2; i <= 102; i++) {
      p[i] = p[i - 1] * i % 998244353;
      inv[i] = (998244353 - (998244353 / i)) * inv[998244353 % i] % 998244353;
    }
    for (long long i = 2; i <= 102; i++)
      inv[i] = inv[i] * inv[i - 1] % 998244353;
    long long m;
    scanf("%lld", &m);
    while (m--) {
      long long ans = 1, sx = 0, sy = 0, x, y;
      scanf("%lld %lld", &x, &y);
      for (long long i = 1; i <= cnt; i++) {
        long long xa = 0, yb = 0, mx = 0;
        while (x % s[i] == 0) {
          x /= s[i];
          xa++;
        }
        while (y % s[i] == 0) {
          y /= s[i];
          yb++;
        }
        mx = max(xa, yb);
        sx += mx - xa;
        sy += mx - yb;
        ans = ans * C(sx, mx - xa) % 998244353 * C(sy, mx - yb) % 998244353;
      }
      printf("%lld\n", ans % 998244353);
    }
  }
}
