#include <bits/stdc++.h>
using namespace std;
long long int fact[51];
long long int pw(long long int a, long long int n) {
  if (n == 0) return 1;
  long long int val = pw(a, n / 2);
  val = (val * val) % 998244353;
  if (n % 2) val = (val * a) % 998244353;
  return val;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int D;
  cin >> D;
  fact[0] = 1;
  for (long long int i = 1; i <= 50; i++)
    fact[i] = (fact[i - 1] * i) % 998244353;
  vector<long long int> div;
  long long int num = D;
  for (long long int i = 2; i * i <= num; i++) {
    if (num % i == 0) div.push_back(i);
    while (num % i == 0) num = num / i;
  }
  if (num != 1) div.push_back(num);
  long long int leng = div.size();
  long long int q, v, u;
  cin >> q;
  while (q--) {
    cin >> v >> u;
    vector<long long int> vp(leng, 0), up(leng, 0), lcm(leng, 0);
    long long int dn = 1;
    long long int u_num = 0;
    long long int v_num = 0;
    for (long long int i = 0; i < leng; i++) {
      long long int no = div[i];
      while (v % no == 0) {
        v /= no;
        vp[i] = (vp[i] + 1) % 998244353;
      }
      while (u % no == 0) {
        u /= no;
        up[i] = (up[i] + 1) % 998244353;
      }
      lcm[i] = max(vp[i], up[i]);
      u_num = (u_num + (lcm[i] - up[i])) % 998244353;
      v_num = (v_num + (lcm[i] - vp[i])) % 998244353;
      dn = (dn * fact[lcm[i] - up[i]]) % 998244353;
      dn = (dn * fact[lcm[i] - vp[i]]) % 998244353;
    }
    long long int ans = (fact[u_num] * fact[v_num]) % 998244353;
    ans = (ans * pw(dn, 998244353 - 2)) % 998244353;
    cout << ans << '\n';
  }
}
