#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using pii = pair<ll, ll>;
using vi = vector<ll>;
const ll P = 998244353;
ll n_, n, q, u, v, fac[1111111], inv[1111111];
ll qpow(ll a, ll b) {
  ll ret = 1;
  while (b) {
    if (b & 1) ret = ret * a % P;
    a = a * a % P;
    b >>= 1;
  }
  return ret;
}
ll c(ll n, ll m) { return fac[n] * inv[m] % P * inv[n - m] % P; }
signed main() {
  scanf("%lld %lld", &n_, &q);
  n = n_;
  vi pr;
  for (ll i = 2; i * i <= n; i++)
    if (n % i == 0) {
      pr.push_back(i);
      while (n % i == 0) n /= i;
    }
  fac[0] = 1;
  for (ll i = 1; i <= 1000000; i++) fac[i] = fac[i - 1] * i % P;
  inv[1000000] = qpow(fac[1000000], P - 2);
  for (ll i = 1000000; i; i--) inv[i - 1] = inv[i] * i % P;
  if (n != 1) pr.push_back(n);
  while (q--) {
    scanf("%lld %lld", &u, &v);
    vi eu, ev;
    for (ll i : pr) {
      eu.push_back(0), ev.push_back(0);
      while (u % i == 0) u /= i, eu.back()++;
      while (v % i == 0) v /= i, ev.back()++;
    }
    ll sum = 0, ans = 1;
    for (ll i = 0; i < eu.size(); i++) sum += max(0ll, ev[i] - eu[i]);
    for (ll i = 0; i < eu.size(); i++)
      if (ev[i] > eu[i])
        ans = ans * c(sum, ev[i] - eu[i]) % P, sum -= ev[i] - eu[i];
    sum = 0;
    for (ll i = 0; i < eu.size(); i++) sum += max(0ll, eu[i] - ev[i]);
    for (ll i = 0; i < eu.size(); i++)
      if (eu[i] > ev[i])
        ans = ans * c(sum, eu[i] - ev[i]) % P, sum -= eu[i] - ev[i];
    printf("%lld\n", ans);
  }
  fprintf(stderr, "time=%.4f\n", (db)clock() / CLOCKS_PER_SEC);
  return 0;
}
