#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const double pi = acos(-1.0);
const long long int inf = 0x3f3f3f3f3f3f3f3f;
const long long int mod = 998244353;
bool isPowerOfTwo(int x) { return x && (!(x & (x - 1))); }
void fast() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int modInverse(long long int n, long long int p) {
  return power(n, p - 2, p);
}
long long int ncr(long long int n, long long int r, long long int p) {
  if (r == 0) return 1;
  long long int fac[n + 1];
  fac[0] = 1;
  for (long long int i = 1; i <= n; i++) fac[i] = fac[i - 1] * i % p;
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
map<long long int, vector<int> > mp;
long long int p[N], c[N], cnt;
int ds[N];
long long int f[N];
void init(long long int n) {
  for (long long int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      p[++cnt] = i;
      while (n % i == 0) c[cnt]++, n /= i;
    }
  }
  if (n != 1) p[++cnt] = n, c[cnt] = 1;
  f[0] = 1;
  for (int i = 1; i <= 200; i++) f[i] = f[i - 1] * i % mod;
}
long long int inv(long long int a, long long int b) {
  long long int res = 1;
  while (b) {
    if (b & 1) res = res * a % mod;
    b >>= 1;
    a = a * a % mod;
  }
  return res % mod;
}
long long int sol(long long int n) {
  long long int a = 1, b = 1, tot = 0;
  for (int i = 1; i <= cnt; i++) {
    long long int cntt = 0;
    while (n % p[i] == 0) n /= p[i], cntt++;
    b = b * f[cntt] % mod;
    tot += cntt;
  }
  a = f[tot];
  return a * inv(b, mod - 2) % mod;
}
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
int main() {
  long long int n;
  cin >> n;
  init(n);
  int q;
  cin >> q;
  while (q--) {
    long long int x, y;
    scanf("%lld%lld", &x, &y);
    long long int g = gcd(x, y);
    printf("%lld\n", sol(x / g) * sol(y / g) % mod);
  }
  return 0;
}
