#include <bits/stdc++.h>
using namespace std;
long long gcd(long long x, long long y) {
  return x % y == 0 ? y : gcd(y, x % y);
}
long long fat[123456], mod = 998244353;
bool composite[40000000];
vector<long long> prime;
long long modPow(long long b, long long e) {
  if (e == 0) return 1;
  if (e == 1) return b % mod;
  long long res = modPow(b, e / 2);
  res = (res * res) % mod;
  if (e % 2 != 0) res = (res * (b % mod)) % mod;
  return res;
}
long long solve(long long u) {
  long long res = 1;
  long long p = 0, q = 1;
  for (long long pr : prime) {
    if (pr * pr > u) break;
    long long cnt = 0;
    while (u % pr == 0) {
      cnt++;
      u /= pr;
      ++p;
    }
    if (cnt) {
      q = (q * fat[cnt]) % mod;
    }
  }
  if (u != 1) ++p;
  return (fat[p] * modPow(q, mod - 2)) % mod;
}
int main() {
  long long k;
  cin >> k;
  long long q;
  cin >> q;
  long long root = sqrt(k) + 2;
  for (long long i = 2; i <= root; i++)
    if (!composite[i]) {
      if (k % i == 0) prime.push_back(i);
      for (long long j = i * i; j <= root; j += i) composite[j] = 1;
    }
  fat[0] = 1;
  for (int i = 1; i < 100000; ++i) fat[i] = (fat[i - 1] * i) % mod;
  while (q--) {
    long long u, v;
    scanf("%lld %lld", &u, &v);
    if (u > v) swap(u, v);
    long long g = gcd(u, v);
    u /= g;
    v /= g;
    long long r1 = solve(u);
    long long r2 = solve(v);
    long long res = (r1 * r2) % mod;
    printf("%lld\n", res);
  }
  return 0;
}
