#include <bits/stdc++.h>
using namespace std;
const int N = 50;
long long int power(long long int a, long long int b) {
  long long int ret = 1;
  for (int i = 0; i < 30; i++) {
    if ((1 << i) & b) {
      ret = (ret * a) % 998244353;
    }
    a = (a * a) % 998244353;
  }
  return ret;
}
long long int f[N], inv[N];
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
vector<long long int> prime;
long long int calc(long long int x) {
  long long int ret = 1;
  int cnt = 0;
  for (auto it : prime) {
    int c = 0;
    while (x % it == 0) {
      c++, cnt++;
      x /= it;
    }
    ret = (ret * inv[c]) % 998244353;
  }
  return (f[cnt] * ret) % 998244353;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  f[0] = 1;
  for (int i = 1; i < N; i++) {
    f[i] = (f[i - 1] * i) % 998244353;
  }
  inv[N - 1] = power(f[N - 1], 998244353 - 2);
  for (int i = N - 2; i >= 0; i--) {
    inv[i] = (inv[i + 1] * (i + 1)) % 998244353;
  }
  long long int d;
  cin >> d;
  for (int i = 2; (long long int)i * i <= d; i++) {
    if (d % i == 0) {
      prime.push_back(i);
      while (d % i == 0) {
        d /= i;
      }
    }
  }
  if (d > 1) prime.push_back(d);
  int q;
  cin >> q;
  while (q--) {
    long long int u, v;
    cin >> u >> v;
    long long int g = gcd(u, v);
    long long int ans = (calc(u / g) * calc(v / g)) % 998244353;
    cout << ans << "\n";
  }
}
