#include <bits/stdc++.h>
using namespace std;
void swap(long long int &a, long long int &b) {
  long long int temp = a;
  a = b;
  b = temp;
}
long long int power(long long int a, long long int b) {
  long long int ans = 1;
  while (b) {
    if (b % 2) ans = (ans * a) % 998244353;
    a = (a * a) % 998244353;
    b = b >> 1;
  }
  return ans;
}
long long int gcd(long long int a, long long int b) {
  if (a < b) swap(a, b);
  if (!b) return a;
  return gcd(b, a % b);
}
struct node {
  long long int a, b;
};
vector<vector<long long int> > graph;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(NULL));
  long long int d;
  cin >> d;
  long long int fact[100000];
  fact[0] = 1;
  fact[1] = 1;
  for (long long int i = 2; i < 100000; ++i)
    fact[i] = (i * fact[i - 1]) % 998244353;
  long long int invmod[100000];
  for (long long int i = 1; i < 100000; ++i)
    invmod[i] = power(fact[i], 998244353 - 2);
  vector<long long int> vals;
  long long int temp = sqrt(d) + 1000;
  for (long long int i = 2; i < temp; ++i) {
    if (d % i == 0) {
      vals.push_back(i);
      while (d % i == 0) d /= i;
    }
  }
  if (d != 1) vals.push_back(d);
  long long int q;
  cin >> q;
  for (long long int i = 0; i < q; ++i) {
    long long int u, v;
    cin >> u >> v;
    long long int gc = gcd(u, v);
    u /= gc;
    v /= gc;
    long long int a1 = 1;
    vector<long long int> v1;
    long long int sum = 0;
    for (auto j : vals) {
      if (u % j == 0) {
        long long int cnt = 0;
        while (u % j == 0) u /= j, cnt++;
        v1.push_back(cnt);
        sum += cnt;
      }
    }
    a1 = (a1 * fact[sum]) % 998244353;
    for (auto j : v1) {
      a1 = (a1 * invmod[j]) % 998244353;
    }
    long long int a2 = 1;
    vector<long long int> v2;
    sum = 0;
    for (auto j : vals) {
      if (v % j == 0) {
        long long int cnt = 0;
        while (v % j == 0) v /= j, cnt++;
        v2.push_back(cnt);
        sum += cnt;
      }
    }
    a2 = (a2 * fact[sum]) % 998244353;
    for (auto j : v2) {
      a2 = (a2 * invmod[j]) % 998244353;
    }
    long long int ans = (a1 * a2) % 998244353;
    cout << ans << "\n";
  }
  return 0;
}
