#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &ret) {
  char c;
  int sgn;
  if (c = getchar(), c == EOF) return;
  while (c != '-' && (c < '0' || c > '9')) c = getchar();
  sgn = (c == '-') ? -1 : 1;
  ret = (c == '-') ? 0 : (c - '0');
  while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
  ret *= sgn;
  return;
}
inline void out(long long x) {
  if (x > 9) out(x / 10);
  putchar(x % 10 + '0');
}
const int mod = 998244353;
const int maxn = 1e5 + 10;
map<long long, int> mp;
long long fac[maxn] = {0};
long long quickpow(long long a, long long b) {
  long long ans = 1, base = a;
  while (b) {
    if (b & 1) ans = ans * base % mod;
    base = base * base % mod;
    b >>= 1;
  }
  return ans;
}
long long C(int m, int n) {
  return fac[n] * quickpow(fac[m] * fac[n - m] % mod, mod - 2) % mod;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int cal(long long n) {
  vector<int> v;
  for (long long i = 2; i <= sqrt(n); i++) {
    int cnt = 0;
    while (n % i == 0) cnt++, n /= i;
    if (cnt) v.push_back(cnt);
  }
  if (n > 1) v.push_back(1);
  long long ans = 1;
  int sum = 0;
  for (int i = 0; i < v.size(); i++) {
    int x = v[i];
    sum += x;
    ans = ans * C(x, sum) % mod;
  }
  return ans;
}
int main() {
  long long d, q, u, v;
  read(d);
  fac[1] = 1, fac[0] = 1;
  for (int i = 2; i < maxn; i++) {
    fac[i] = fac[i - 1] * i % mod;
  }
  for (int i = 1; i <= sqrt(d); i++) {
    if (d % i == 0) {
      mp[i] = cal(i);
      mp[d / i] = cal(d / i);
    }
  }
  read(q);
  while (q--) {
    read(u), read(v);
    long long gc = gcd(u, v);
    out(1ll * mp[u / gc] * mp[v / gc] % mod);
    putchar('\n');
  }
  return 0;
}
