#include <bits/stdc++.h>
using namespace std;
long long mod = (998244353LL);
inline long long Mod(long long a, long long b) { return (a % b); }
inline long long poww(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b, swap(a, b);
  }
  return a;
}
void read(vector<long long> &w, long long n) {
  w.resize(n);
  for (long long i = 0; i < n; i++) cin >> w[i];
}
void print(vector<long long> &w) {
  for (long long i = 0; i < (long long)(w).size(); i++) {
    if (i == (long long)(w).size() - 1)
      cout << w[i] << "\n";
    else
      cout << w[i] << " ";
  }
}
long long n, m, q, k, v[300050], ans;
pair<long long, long long> w[300050];
string second;
int32_t main() {
  cin >> n >> q;
  vector<long long> primes, fat(500), inv(500);
  fat[0] = 1LL;
  inv[0] = 1LL;
  for (long long i = 1; i < 500; i++) {
    fat[i] = (i * fat[i - 1]) % mod;
    inv[i] = poww(fat[i], mod - 2);
  }
  for (long long i = 2; i * i <= n; i++) {
    long long cnt = 0;
    while (n % i == 0) {
      cnt++;
      n /= i;
    }
    if (cnt > 0) primes.push_back(i);
  }
  if (n > 1) primes.push_back(n);
  while (q--) {
    long long a, b;
    cin >> a >> b;
    long long x = gcd(a, b);
    long long A = a / x, B = b / x, ans = 1LL;
    long long tota = 0, totb = 0;
    for (auto p : primes) {
      long long qa = 0, qb = 0;
      while (A % p == 0) {
        qa++;
        A /= p;
      }
      while (B % p == 0) {
        qb++;
        B /= p;
      }
      tota += qa;
      totb += qb;
      long long inA = inv[qa];
      long long inB = inv[qb];
      ans = Mod(inB * Mod(inA * ans, mod), mod);
    }
    ans = Mod(fat[totb] * Mod(ans * fat[tota], mod), mod);
    cout << ans << "\n";
  }
}
