#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
int n, m, k, sum1, sum2, tot;
long long s, t, now, ans, a[N], b[N], D;
long long C[1001][1001];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 0; i <= 1000; ++i) {
    C[i][0] = 1;
    for (int j = 1; j <= i; ++j)
      C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % 998244353;
  }
  cin >> D;
  for (long long i = 2; i * i <= D; ++i) {
    if (D % i == 0) {
      a[++tot] = i;
      while (D % i == 0) D /= i;
    }
  }
  if (D != 1) a[++tot] = D;
  int T;
  cin >> T;
  while (T--) {
    cin >> s >> t;
    sum1 = sum2 = 0;
    for (int i = 1; i <= tot; ++i) {
      k = 0;
      while (s % a[i] == 0) {
        ++k;
        s /= a[i];
      }
      while (t % a[i] == 0) {
        --k;
        t /= a[i];
      }
      if (k < 0)
        sum1 += (-k);
      else
        sum2 += k;
      b[i] = k;
    }
    ans = 1;
    for (int i = 1; i <= tot; ++i) {
      if (b[i] < 0) {
        b[i] = -b[i];
        ans = ans * C[sum1][b[i]] % 998244353;
        sum1 -= b[i];
      } else {
        ans = ans * C[sum2][b[i]] % 998244353;
        sum2 -= b[i];
      }
    }
    cout << ans << "\n";
  }
}
