#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
const long long mod = 998244353;
long long binpow(long long a, long long n) {
  if (n == 0) return 1;
  if (n % 2 == 1) {
    return (binpow(a, n - 1) * a) % mod;
    ;
  } else {
    long long b = binpow(a, n / 2);
    return (b * b) % mod;
  }
}
long long f[500];
long long f_obr[500];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  f[0] = 1;
  f_obr[0] = 1;
  for (long long i = 1; i < 500; ++i) {
    f[i] = f[i - 1] * i;
    f[i] %= mod;
    f_obr[i] = binpow(f[i], mod - 2);
  }
  long long d;
  cin >> d;
  vector<long long> pr;
  pr.reserve(1e7 + 5);
  for (long long i = 2; i * i <= d; ++i) {
    if (d % i == 0) {
      pr.push_back(i);
      while (d % i == 0) d /= i;
    }
  }
  if (d > 1) pr.push_back(d);
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    long long v[2];
    cin >> v[0] >> v[1];
    vector<long long> vc[2];
    vector<int> cnt[2];
    for (int j = 0; j < 2; ++j)
      for (int k = 0; k < int(pr.size()); ++k)
        if (v[j] % pr[k] == 0) {
          vc[j].push_back(pr[k]);
          cnt[j].push_back(0);
          while (v[j] % pr[k] == 0) {
            cnt[j].back()++;
            v[j] /= pr[k];
          }
        }
    int uk = 0;
    vector<int> res[2];
    for (int j = 0; j < int(cnt[0].size()); ++j) {
      while (uk < int(cnt[1].size()) && vc[1][uk] <= vc[0][j]) {
        if (vc[1][uk] == vc[0][j]) {
          if (cnt[0][j] > cnt[1][uk])
            res[0].push_back(cnt[0][j] - cnt[1][uk]);
          else
            res[1].push_back(cnt[1][uk] - cnt[0][j]);
        } else
          res[1].push_back(cnt[1][uk]);
        ++uk;
      }
      if (!(uk > 0 && vc[1][uk - 1] == vc[0][j])) res[0].push_back(cnt[0][j]);
    }
    while (uk < int(cnt[1].size())) {
      res[1].push_back(cnt[1][uk]);
      ++uk;
    }
    int sum[2];
    sum[0] = 0;
    sum[1] = 0;
    long long ans = 1;
    for (int j = 0; j < 2; ++j)
      for (int k = 0; k < int(res[j].size()); ++k) {
        sum[j] += res[j][k];
        ans *= f_obr[res[j][k]];
        ans %= mod;
      }
    ans *= f[sum[0]];
    ans %= mod;
    ans *= f[sum[1]];
    ans %= mod;
    cout << ans << '\n';
  }
  return 0;
}
