#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
vector<long long> fact, ifact, invs;
long long combmod(int n, int k, long long MOD, int M = 1e5) {
  if (!fact.size()) {
    fact.resize(M + 1);
    ifact.resize(M + 1);
    invs.resize(M + 1);
    fact[0] = ifact[0] = invs[0] = fact[1] = ifact[1] = invs[1] = 1;
    for (int i = 2; i <= M; i++) {
      fact[i] = fact[i - 1] * i % MOD;
      invs[i] = MOD - MOD / i * invs[MOD % i] % MOD;
      ifact[i] = ifact[i - 1] * invs[i] % MOD;
    }
  }
  return fact[n] * ifact[k] % MOD * ifact[n - k] % MOD;
}
int main(int argc, char** argv) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << setprecision(15);
  if (argc == 2 && atoi(argv[1]) == 123456789) {
    freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);
  }
  combmod(1, 1, MOD, 1e2);
  long long D;
  cin >> D;
  vector<long long> ps;
  long long p = 2;
  while (p * p <= D) {
    int e = 0;
    if (D % p == 0) ps.push_back(p);
    while (D % p == 0) {
      e++;
      D /= p;
    }
    p++;
  }
  if (D > 1) ps.push_back(D);
  int q;
  cin >> q;
  for (int(i) = 0; (i) < (q); (i)++) {
    long long u, v;
    cin >> u >> v;
    int a[100] = {}, b[100] = {};
    for (int k = 0; k < ps.size(); k++) {
      while (u % ps[k] == 0) {
        u /= ps[k];
        a[k]++;
      }
      while (v % ps[k] == 0) {
        v /= ps[k];
        b[k]++;
      }
    }
    long long sol = 1;
    int s1 = 0, s2 = 0;
    for (int k = 0; k < ps.size(); k++) {
      int g = min(a[k], b[k]);
      s1 += a[k] - g;
      s2 += b[k] - g;
      sol *= ifact[a[k] - g];
      sol %= MOD;
      sol *= ifact[b[k] - g];
      sol %= MOD;
    }
    sol *= fact[s1];
    sol %= MOD;
    sol *= fact[s2];
    sol %= MOD;
    cout << sol << endl;
  }
  if (argc == 2 && atoi(argv[1]) == 123456789)
    cout << clock() * 1.0 / CLOCKS_PER_SEC << " sec\n";
  return 0;
}
