#include <bits/stdc++.h>
using namespace std;
const long long maxn = 4e5 + 10;
const long long mod = 998244353;
const long long inf = 1e18 + 10;
const long long Log = 21;
long long n, m, k;
long long pw(long long a, long long b) {
  if (b == 0) return 1;
  long long x = pw(a, b / 2);
  x = (x * x) % mod;
  if (b & 1) x = (x * a) % mod;
  return x;
}
long long cnt(long long x, long long p) {
  long long X = 0;
  while (x % p == 0) {
    x /= p;
    X++;
  }
  return X;
}
long long D;
vector<long long> pr;
long long fac[maxn], repo[maxn];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  fac[0] = 1;
  repo[0] = 1;
  for (long long i = 1; i < 200; i++) {
    fac[i] = (fac[i - 1] * i) % mod;
    repo[i] = pw(fac[i], mod - 2);
  }
  cin >> D;
  for (long long i = 2; i <= sqrt(D); i++)
    if (D % i == 0) {
      while (D % i == 0) D /= i;
      pr.push_back(i);
    }
  if (D > 1) pr.push_back(D);
  long long q;
  cin >> q;
  while (q--) {
    long long u, v;
    cin >> u >> v;
    if (u > v) swap(u, v);
    long long ans = 1, sm2 = 0, sm1 = 0;
    for (auto p : pr) {
      long long x = cnt(u, p);
      long long y = cnt(v, p);
      (ans *= repo[abs(x - y)]) %= mod;
      if (x < y) sm1 += y - x;
      if (x > y) sm2 += x - y;
    }
    (ans *= (fac[sm1] * fac[sm2]) % mod) %= mod;
    cout << ans << "\n";
  }
}
