#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 10;
const ll M = 998244353;
ll d;
int q;
vector<ll> dpd, fact, afact;
ll gcd(ll a, ll b) {
  while (a > 0 && b > 0) {
    if (a > b)
      a %= b;
    else
      b %= a;
  }
  return a + b;
}
ll pw(ll a, ll n) {
  if (n == 0) return 1;
  if (n & 1) return a * pw(a, n - 1) % M;
  ll temp = pw(a, n >> 1);
  return temp * temp % M;
}
void count_dpd() {
  ll x = d;
  for (ll i = 2; i * i <= x; i++) {
    if (x % i == 0) dpd.push_back(i);
    while (x % i == 0) x /= i;
  }
  if (x > 1) dpd.push_back(x);
}
void count_fact() {
  fact.push_back(1);
  afact.push_back(1);
  for (int i = 1; i < N; i++) {
    fact.push_back((fact.back() * i) % M);
    afact.push_back((afact.back() * pw(i, M - 2)) % M);
  }
}
ll answer(ll a) {
  vector<int> ks;
  int k = 0;
  for (ll x : dpd) {
    ks.push_back(0);
    while (a % x == 0) {
      ks.back()++;
      a /= x;
    }
    k += ks.back();
    if (ks.back() == 0) ks.pop_back();
  }
  ll ans = fact[k];
  for (ll x : ks) ans = (ans * afact[x]) % M;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> d >> q;
  count_dpd();
  count_fact();
  while (q--) {
    ll v, u;
    cin >> v >> u;
    ll g = gcd(v, u);
    cout << (answer(v / g) * answer(u / g)) % M << '\n';
  }
  return 0;
}
