#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MOD=998244353;
ll lgcput(ll base,ll pow){
  ll ans=1;
  while(pow){
    if(pow&1){
      ans*=base;
      ans%=MOD;
    }
    pow/=2;
    base*=base;
    base%=MOD;
  }
  return ans;
}
const int N=1e2;
ll fact[N];
vector<ll> dv;
map<ll,ll> getdiv(ll d){
  map<ll,ll> ans;
  ll dvz=2;
  while(dvz*dvz<=d){
    ll pw=0;
    while(d%dvz==0){
      d/=dvz;
      pw++;
    }
    ans[dvz]=pw;
    dvz++;
  }
  if(d!=1){
    ans[d]=1;
  }
  return ans;
}
ll getpow(ll x,ll div){
  ll ans=0;
  while(x%div==0){
    x/=div;
    ans++;
  }
  return ans;
}
ll permcurep(vector<int> v){
  ll ans=1;
  ll s=0;
  for(auto i:v)
    s+=i;
  ans=fact[s];
  for(auto i:v){
    if(i>1){
      ans*=lgcput(fact[i],MOD-2);
      ans%=MOD;
    }
  }
  return ans;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  fact[1]=fact[0]=1;
  for(int i=1;i<N;i++){
    fact[i]=i*fact[i-1];
    fact[i]%=MOD;
  }
  ll d;
  cin>>d;
  ll dvz=2;
  while(dvz*dvz<=d){
    ll pw=0;
    while(d%dvz==0){
      d/=dvz;
      pw++;
    }
    dv.push_back(dvz);
    dvz++;
  }
  if(d!=1){
    dv.push_back(d);
  }
  int querys;
  cin>>querys;

  for(int i=1;i<=querys;i++){
    ll v,u;
    cin>>v>>u;
    if(v<u)
      swap(v,u);
    vector<int> del;
    vector<int> ad;
    for(auto x:dv){
      ll powu=getpow(u,x);
      ll powv=getpow(v,x);
      if(powu<powv)
        ad.push_back(powv-powu);
      else if(powv<powu){
        del.push_back(powu-powv);
      }
    }
    ll ans=permcurep(ad);
    ans*=permcurep(del);
    ans%=MOD;
    cout<<ans<<"\n";
  }
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MOD=998244353;
ll lgcput(ll base,ll pow){
  ll ans=1;
  while(pow){
    if(pow&1){
      ans*=base;
      ans%=MOD;
    }
    pow/=2;
    base*=base;
    base%=MOD;
  }
  return ans;
}
const int N=1e4;
ll fact[N];
map<ll,ll> dv;
map<ll,ll> getdiv(ll d){
  map<ll,ll> ans;
  ll dvz=2;
  while(dvz*dvz<=d){
    ll pw=0;
    while(d%dvz==0){
      d/=dvz;
      pw++;
    }
    ans[dvz]=pw;
    dvz++;
  }
  if(d!=1){
    ans[d]=1;
  }
  return ans;
}
ll permcurep(vector<int> v){
  ll ans=1;
  ll s=0;
  for(auto i:v)
    s+=i;
  ans=fact[s];
  for(auto i:v){
    if(i>1){
      ans*=lgcput(fact[i],MOD-2);
      ans%=MOD;
    }
  }
  return ans;
}
int main()
{
  fact[1]=fact[0]=1;
  for(int i=1;i<N;i++){
    fact[i]=i*fact[i-1];
    fact[i]%=MOD;
  }
  ll d;
  cin>>d;
  dv=getdiv(d);
  int querys;
  cin>>querys;

  for(int i=1;i<=querys;i++){
    ll v,u;
    cin>>v>>u;
    if(v<u)
      swap(v,u);
    map<ll,ll> dvu,dvv;
    dvu=getdiv(u);
    dvv=getdiv(v);
    vector<int> del;
    vector<int> ad;
    for(auto x:dv){
      ll powu=dvu[x.first];
      ll powv=dvv[x.first];
      if(powu<powv)
        ad.push_back(powv-powu);
      else if(powv<powu){
        del.push_back(powu-powv);
      }
    }
    ll ans=permcurep(ad);
    ans*=permcurep(del);
    ans%=MOD;
    cout<<ans<<"\n";
  }
  return 0;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int MOD=998244353;
ll lgcput(ll base,ll pow){
  ll ans=1;
  while(pow){
    if(pow&1){
      ans*=base;
      ans%=MOD;
    }
    pow/=2;
    base*=base;
    base%=MOD;
  }
  return ans;
}
const int N=1e4;
ll fact[N];
vector<ll> dv;
map<ll,ll> getdiv(ll d){
  map<ll,ll> ans;
  ll dvz=2;
  while(dvz*dvz<=d){
    ll pw=0;
    while(d%dvz==0){
      d/=dvz;
      pw++;
    }
    ans[dvz]=pw;
    dvz++;
  }
  if(d!=1){
    ans[d]=1;
  }
  return ans;
}
ll permcurep(vector<int> v){
  ll ans=1;
  ll s=0;
  for(auto i:v)
    s+=i;
  ans=fact[s];
  for(auto i:v){
    if(i>1){
      ans*=lgcput(fact[i],MOD-2);
      ans%=MOD;
    }
  }
  return ans;
}
int main()
{
  fact[1]=fact[0]=1;
  for(int i=1;i<N;i++){
    fact[i]=i*fact[i-1];
    fact[i]%=MOD;
  }
  ll d;
  cin>>d;
  ll dvz=2;
  while(dvz*dvz<=d){
    ll pw=0;
    while(d%dvz==0){
      d/=dvz;
      pw++;
    }
    dv.push_back(dvz);
    dvz++;
  }
  if(d!=1){
    dv.push_back(d);
  }
  int querys;
  cin>>querys;

  for(int i=1;i<=querys;i++){
    ll v,u;
    cin>>v>>u;
    if(v<u)
      swap(v,u);
    map<ll,ll> dvu,dvv;
    dvu=getdiv(u);
    dvv=getdiv(v);
    vector<int> del;
    vector<int> ad;
    for(auto x:dv){
      ll powu=dvu[x];
      ll powv=dvv[x];
      if(powu<powv)
        ad.push_back(powv-powu);
      else if(powv<powu){
        del.push_back(powu-powv);
      }
    }
    ll ans=permcurep(ad);
    ans*=permcurep(del);
    ans%=MOD;
    cout<<ans<<"\n";
  }
  return 0;
}


#include<bits/stdc++.h>

using namespace std;

#define fr(i, n) for(ll i = 0; i < n; i++)
#define frr(i, n) for(ll i = 1; i <= n; i++)
#define frm(i, n) for(ll i = n-1; i >= 0; i--)

#define pb push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<double, double> ponto;
typedef vector<vector<ll>> matrix;

#define mem(v, k) memset(v, k, sizeof(v));

#define db cout << "Debug" << endl;

#define mp make_pair
#define pq priority_queue

#define mx(a, b) a = max(a, b);
#define mod(a, b) a = a%b;

#define MAXN 100010
#define MOD 998244353
#define MAXL 30
#define ROOT 1
#define INF 987654321

ll gcd(ll a, ll b){
	if(b == 0) return a;
	else return gcd(b, a%b);
}

ll fastxp(ll b, ll e){
	if(e == 1) return b;
	else{
		ll ans = fastxp(b, e/2);
		ans = (ans*ans)%MOD;

		if(e%2 == 1) ans = (ans*b)%MOD;

		return ans;
	}
}

ll fac[MAXN], ifac[MAXN];
ll prime[MAXN];
vector<ll> p;
map<ll, ll> m;

void build(){

	fac[0] = 1;
	frr(i, 100000) {
		fac[i] = (fac[i-1]*i)%MOD;
		ifac[i] = fastxp(fac[i], MOD - 2);
	}

	for(ll i = 2; i < MAXN; i++){
		if(prime[i] == 0){
			p.pb(i);

			for(ll j = 2; j*i < MAXN; j++){
				prime[i*j] = 1;
			}
		}
	}
}

ll ans(ll a){
	if(m[a] != 0){

		return m[a];
	}

	ll ret = 0, A = a;
	vector<ll> v;

	for(ll x: p){
		if(a%x == 0){
			ll aux = 0;
			while(a%x == 0){
				a /= x;
				aux++;
			}

			ret+=aux;
			v.pb(aux);
		}
	}

	if(a > 1){
		ll s = sqrt(a);

		if(s*s == a || (s+1)*(s+1) == a){
			ret+=2;
			v.pb(2);
		}
	}

	ret = fac[ret];

	for(ll x: v){
		ret = (ret*ifac[x])%MOD;
	}

	m[A] = ret;
	//cout << a << " " << ret << endl;

	return ret;
}

int main(){
	build();

	ll d, q;
	scanf("%lld %lld", &d, &q);

	while(q--){
		ll a, b;
		scanf("%lld %lld", &a, &b);

		ll g = gcd(a, b);

		printf("%lld\n", (ans(a/g)*ans(b/g))%MOD);
	}

}


#include<bits/stdc++.h>

using namespace std;

#define fr(i, n) for(ll i = 0; i < n; i++)
#define frr(i, n) for(ll i = 1; i <= n; i++)
#define frm(i, n) for(ll i = n-1; i >= 0; i--)

#define pb push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<double, double> ponto;
typedef vector<vector<ll>> matrix;

#define mem(v, k) memset(v, k, sizeof(v));

#define db cout << "Debug" << endl;

#define mp make_pair
#define pq priority_queue

#define mx(a, b) a = max(a, b);
#define mod(a, b) a = a%b;

#define MAXN 100010
#define MOD 998244353
#define MAXL 30
#define ROOT 1
#define INF 987654321

ll gcd(ll a, ll b){
	//cout << a << " " << b << endl;

	if(b == 0) return a;
	else return gcd(b, a%b);
}

ll fastxp(ll b, ll e){
	if(e == 1) return b;
	else{
		ll ans = fastxp(b, e/2);
		ans = (ans*ans)%MOD;

		if(e%2 == 1) ans = (ans*b)%MOD;

		return ans;
	}
}

ll fac[MAXN], ifac[MAXN];
ll prime[MAXN];
vector<ll> p;

void build(){

	fac[0] = 1;
	frr(i, 100000) {
		fac[i] = (fac[i-1]*i)%MOD;
		ifac[i] = fastxp(fac[i], MOD - 2);
	}

	for(ll i = 2; i < MAXN; i++){
		if(prime[i] == 0){
			p.pb(i);

			for(ll j = 2; j*i < MAXN; j++){
				prime[i*j] = 1;
			}
		}
	}
}

ll ans(ll a){
	ll ret = 0;
	vector<ll> v;

	for(ll x: p){
		if(a%x == 0){
			ll aux = 0;
			while(a%x == 0){
				a /= x;
				aux++;
			}

			ret+=aux;
			v.pb(aux);
		}
	}

	if(a > 1){
		ll s = sqrt(a);

		if(s*s == a || (s+1)*(s+1) == a){
			ret+=2;
			v.pb(2);
		}
	}

	ret = fac[ret];

	for(ll x: v){
		ret = (ret*ifac[x])%MOD;
	}

	return ret;
}

int main(){
	build();

	ll d, q;
	scanf("%lld %lld", &d, &q);
	cin >> d >> q;

	while(q--){
		ll a, b;
		scanf("%lld %lld", &a, &b);

		ll g = gcd(a, b);
/*
		cout<< endl;
		cout << a/g << " " << g <<endl;
*/
		printf("%lld\n", (ans(a/g)*ans(b/g))%MOD);

	}

}


#include<bits/stdc++.h>

using namespace std;

#define fr(i, n) for(ll i = 0; i < n; i++)
#define frr(i, n) for(ll i = 1; i <= n; i++)
#define frm(i, n) for(ll i = n-1; i >= 0; i--)

#define pb push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<double, double> ponto;
typedef vector<vector<ll>> matrix;

#define mem(v, k) memset(v, k, sizeof(v));

#define db cout << "Debug" << endl;

#define mp make_pair
#define pq priority_queue

#define mx(a, b) a = max(a, b);
#define mod(a, b) a = a%b;

#define MAXN 100010
#define MOD 998244353
#define MAXL 30
#define ROOT 1
#define INF 987654321

ll gcd(ll a, ll b){
	//cout << a << " " << b << endl;

	if(b == 0) return a;
	else return gcd(b, a%b);
}

ll fastxp(ll b, ll e){
	if(e == 1) return b;
	else{
		ll ans = fastxp(b, e/2);
		ans = (ans*ans)%MOD;

		if(e%2 == 1) ans = (ans*b)%MOD;

		return ans;
	}
}

ll fac[MAXN], ifac[MAXN];
ll prime[MAXN];
vector<ll> p;

void build(){

	fac[0] = 1;
	frr(i, 100000) {
		fac[i] = (fac[i-1]*i)%MOD;
		ifac[i] = fastxp(fac[i], MOD - 2);
	}

	for(ll i = 2; i < MAXN; i++){
		if(prime[i] == 0){
			p.pb(i);

			for(ll j = 2; j*i < MAXN; j++){
				prime[i*j] = 1;
			}
		}
	}
}

ll ans(ll a){
	ll ret = 0;
	vector<ll> v;

	for(ll x: p){
		if(a%x == 0){
			ll aux = 0;
			while(a%x == 0){
				a /= x;
				aux++;
			}

			ret+=aux;
			v.pb(aux);
		}
	}

	if(a > 1){
		ll s = sqrt(a);

		if(s*s == a || (s+1)*(s+1) == a){
			ret+=2;
			v.pb(2);
		}
	}

	ret = fac[ret];

	for(ll x: v){
		ret = (ret*ifac[x])%MOD;
	}

	return ret;
}

int main(){
	build();

	ll d, q;
	scanf("%lld %lld", &d, &q);

	while(q--){
		ll a, b;
		scanf("%lld %lld", &a, &b);

		ll g = gcd(a, b);
/*
		cout<< endl;
		cout << a/g << " " << g <<endl;
*/
		printf("%lld\n", (ans(a/g)*ans(b/g))%MOD);

	}

}


#include<bits/stdc++.h>

using namespace std;

#define fr(i, n) for(ll i = 0; i < n; i++)
#define frr(i, n) for(ll i = 1; i <= n; i++)
#define frm(i, n) for(ll i = n-1; i >= 0; i--)

#define pb push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<double, double> ponto;
typedef vector<vector<ll>> matrix;

#define mem(v, k) memset(v, k, sizeof(v));

#define db cout << "Debug" << endl;

#define mp make_pair
#define pq priority_queue

#define mx(a, b) a = max(a, b);
#define mod(a, b) a = a%b;

#define MAXN 100010
#define MOD 998244353
#define MAXL 30
#define ROOT 1
#define INF 987654321

ll gcd(ll a, ll b){
	if(b == 0) return a;
	else return gcd(b, a%b);
}

ll fastxp(ll b, ll e){
	if(e == 1) return b;
	else{
		ll ans = fastxp(b, e/2);
		ans = (ans*ans)%MOD;

		if(e%2 == 1) ans = (ans*b)%MOD;

		return ans;
	}
}

ll fac[MAXN], ifac[MAXN];
vector<ll> p;
map<ll, ll> m;
ll d, q;

void build(){

	fac[0] = 1;
	frr(i, 100000) {
		fac[i] = (fac[i-1]*i)%MOD;
		ifac[i] = fastxp(fac[i], MOD - 2);
	}

	ll i = 2;

	while(i*i <= d){
		if(d%i == 0){
			p.pb(i);
			while(i*i <= d && d%i == 0) d /= i;
		}
		i++;
	}

	if(d > 1) p.pb(d);
}

ll ans(ll a){
	if(m[a] != 0){

		return m[a];
	}

	ll ret = 0, A = a;
	vector<ll> v;

	for(ll x: p){
		if(a%x == 0){
			ll aux = 0;
			while(a%x == 0){
				a /= x;
				aux++;
			}

			ret+=aux;
			v.pb(aux);

		}
	}

	ret = fac[ret];

	for(ll x: v){
		ret = (ret*ifac[x])%MOD;
	}

	m[A] = ret;
	//cout << a << " " << ret << endl;

	return ret;
}

int main(){
	scanf("%lld %lld", &d, &q);

	build();

	while(q--){
		ll a, b;
		scanf("%lld %lld", &a, &b);

		ll g = gcd(a, b);

		printf("%lld\n", (ans(a/g)*ans(b/g))%MOD);
	}

}


#include<bits/stdc++.h>

using namespace std;

#define fr(i, n) for(ll i = 0; i < n; i++)
#define frr(i, n) for(ll i = 1; i <= n; i++)
#define frm(i, n) for(ll i = n-1; i >= 0; i--)

#define pb push_back
#define f first
#define s second

typedef long long ll;
typedef pair<ll,ll> pii;
typedef pair<double, double> ponto;
typedef vector<vector<ll>> matrix;

#define mem(v, k) memset(v, k, sizeof(v));

#define db cout << "Debug" << endl;

#define mp make_pair
#define pq priority_queue

#define mx(a, b) a = max(a, b);
#define mod(a, b) a = a%b;

#define MAXN 100010
#define MOD 998244353
#define MAXL 30
#define ROOT 1
#define INF 987654321

ll gcd(ll a, ll b){
	//cout << a << " " << b << endl;

	if(b == 0) return a;
	else return gcd(b, a%b);
}

ll fastxp(ll b, ll e){
	if(e == 1) return b;
	else{
		ll ans = fastxp(b, e/2);
		ans = (ans*ans)%MOD;

		if(e%2 == 1) ans = (ans*b)%MOD;

		return ans;
	}
}

ll fac[MAXN], ifac[MAXN];
ll prime[MAXN];
vector<ll> p;

void build(){

	fac[0] = 1;
	frr(i, 100000) {
		fac[i] = (fac[i-1]*i)%MOD;
		ifac[i] = fastxp(fac[i], MOD - 2);
	}

	for(ll i = 2; i < MAXN; i++){
		if(prime[i] == 0){
			p.pb(i);

			for(ll j = 2; j*i < MAXN; j++){
				prime[i*j] = 1;
			}
		}
	}
}

ll ans(ll a){
	ll ret = 0;
	vector<ll> v;

	for(auto x: p){
		if(a%x == 0){
			ll aux = 0;
			while(a%x == 0){
				a /= x;
				aux++;
			}

			ret+=aux;
			v.pb(aux);
		}
	}

	if(a > 1){
		ll s = sqrt(a);

		if(s*s == a || (s+1)*(s+1) == a){
			ret+=2;
			v.pb(2);
		}
	}

	ret = fac[ret];

	for(ll x: v){
		ret = (ret*ifac[x])%MOD;
	}

	return ret;
}

int main(){
	ios::sync_with_stdio(false);

	build();

	ll d, q;
	cin >> d >> q;

	while(q--){
		ll a, b;
		cin >> a >> b;

		ll g = gcd(a, b);
/*
		cout<< endl;
		cout << a/g << " " << g <<endl;
*/
		cout << (ans(a/g)*ans(b/g))%MOD << endl;
	}

}


#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long LL;
const LL mod=998244353;
LL fac[1010], n, a, b;
LL gcd(LL a, LL b){return b?gcd(b, a%b):a;}
LL power(LL a, LL b){
    if(!b)return 1ll;
    LL ret=power(a, b/2);
    if(b%2)return ret*ret%mod*a%mod;
    return ret*ret%mod;
}
int q;
bool ch[35000000];
LL prime[100010];
int re;
int main(){
    scanf("%lld %d", &n, &q);
    fac[0]=1;
    LL tmp=n;
    for(register LL i=2; i*i<=n; i++){
        if(tmp%i==0){
            prime[re++]=i;
            while(tmp%i==0)tmp/=i;
        }
        if(tmp==1)break;
    }
    if(tmp>1)prime[re++]=tmp;
    for(int i=1; i<=1000; i++)fac[i]=fac[i-1]*(LL)i%mod;
    while(q--){
        scanf("%lld %lld", &a, &b);
        LL g=gcd(a, b);
        LL ans=1;
        int sum1=0, sum2=0;
        for(int i=0; i<re; i++){
            int numa=0, numb=0;
            while(a%prime[i]==0){
                numa++;
                a/=prime[i];
            }
            while(b%prime[i]==0){
                numb++;
                b/=prime[i];
            }
            int num=0;
            while(g%prime[i]==0){
                num++;
                g/=prime[i];
            }
            ans*=power(fac[numa-num], mod-2);
            ans%=mod;
            sum1+=numa-num;
            ans*=power(fac[numb-num], mod-2);
            ans%=mod;
            sum2+=numb-num;
        }
        ans*=fac[sum1];
        ans%=mod;
        ans*=fac[sum2];
        ans%=mod;
        printf("%lld\n", ans);
    }
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortvec(x) sort(all(x))
#define compress(x) x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL mod=998244353;
LL fac[1010];
LL n, a, b;
LL gcd(LL a, LL b){return b?gcd(b, a%b):a;}
LL power(LL a, LL b){
    if(!b)return 1;
    LL ret=power(a, b/2);
    if(b%2)return ret*ret%mod*a%mod;
    return ret*ret%mod;
}
int q;
bool ch[35000000];
vector<LL> prime;
int main(){
    scanf("%lld %d", &n, &q);
    fac[0]=1;
    LL tmp=n;
    for(register LL i=2; i*i<=n; i++){
        if(tmp%i==0){
            prime.pb(i);
            while(tmp%i==0)tmp/=i;
        }
        if(tmp==1)break;
    }
    if(tmp>1)prime.pb(tmp);
    for(int i=1; i<=1000; i++)fac[i]=fac[i-1]*(LL)i%mod;
    while(q--){
        scanf("%lld %lld", &a, &b);
        LL g=gcd(a, b);
        vector<int> vca, vcb, vcg;
        vca.resize(prime.size());
        vcb.resize(prime.size());
        vcg.resize(prime.size());
        for(int i=0; i<prime.size(); i++){
            while(a%prime[i]==0){
                vca[i]++;
                a/=prime[i];
            }
        }
        for(int i=0; i<prime.size(); i++){
            while(b%prime[i]==0){
                vcb[i]++;
                b/=prime[i];
            }
        }
        for(int i=0; i<prime.size(); i++){
            while(g%prime[i]==0){
                vcg[i]++;
                g/=prime[i];
            }
        }
        LL ans=1;
        int sum1=0, sum2=0;
        for(int i=0; i<prime.size(); i++){
            ans*=power(fac[vca[i]-vcg[i]], mod-2);
            ans%=mod;
            sum1+=vca[i]-vcg[i];
            ans*=power(fac[vcb[i]-vcg[i]], mod-2);
            ans%=mod;
            sum2+=vcb[i]-vcg[i];
        }
        ans*=fac[sum1];
        ans%=mod;
        ans*=fac[sum2];
        ans%=mod;
        printf("%lld\n", ans);
    }
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortvec(x) sort(all(x))
#define compress(x) x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL mod=998244353;
LL fac[1010];
LL n, a, b;
LL gcd(LL a, LL b){return b?gcd(b, a%b):a;}
LL power(LL a, LL b){
    if(!b)return 1;
    LL ret=power(a, b/2);
    if(b%2)return ret*ret%mod*a%mod;
    return ret*ret%mod;
}
int q;
bool ch[35000000];
vector<LL> prime;
int main(){
    scanf("%lld %d", &n, &q);
    fac[0]=1;
    LL tmp=n;
    for(LL i=2; i*i<=n; i++){
        if(ch[(int)i])continue;
        if(tmp%i==0){
            prime.pb(i);
            while(tmp%i==0)tmp/=i;
        }
        for(LL j=2*i; j*j<=n; j+=i)ch[(int)j]=true;
    }
    if(tmp>1)prime.pb(tmp);
    for(int i=1; i<=1000; i++)fac[i]=fac[i-1]*(LL)i%mod;
    while(q--){
        scanf("%lld %lld", &a, &b);
        LL g=gcd(a, b);
        vector<int> vca, vcb, vcg;
        vca.resize(prime.size());
        vcb.resize(prime.size());
        vcg.resize(prime.size());
        for(int i=0; i<prime.size(); i++){
            while(a%prime[i]==0){
                vca[i]++;
                a/=prime[i];
            }
        }
        for(int i=0; i<prime.size(); i++){
            while(b%prime[i]==0){
                vcb[i]++;
                b/=prime[i];
            }
        }
        for(int i=0; i<prime.size(); i++){
            while(g%prime[i]==0){
                vcg[i]++;
                g/=prime[i];
            }
        }
        LL ans=1;
        int sum1=0, sum2=0;
        for(int i=0; i<prime.size(); i++){
            ans*=power(fac[vca[i]-vcg[i]], mod-2);
            ans%=mod;
            sum1+=vca[i]-vcg[i];
            ans*=power(fac[vcb[i]-vcg[i]], mod-2);
            ans%=mod;
            sum2+=vcb[i]-vcg[i];
        }
        ans*=fac[sum1];
        ans%=mod;
        ans*=fac[sum2];
        ans%=mod;
        printf("%lld\n", ans);
    }
}


#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long LL;
const LL mod=998244353;
LL fac[1010], n, a, b;
LL gcd(LL a, LL b){return b?gcd(b, a%b):a;}
LL power(LL a, LL b){
    if(!b)return 1ll;
    LL ret=power(a, b/2);
    if(b%2)return ret*ret%mod*a%mod;
    return ret*ret%mod;
}
int q;
bool ch[35000000];
LL prime[100010], facinv[1010];
int re;
int main(){
    scanf("%lld %d", &n, &q);
    fac[0]=facinv[0]=1;
    LL tmp=n;
    for(register LL i=2; i*i<=n; i++){
        if(tmp%i==0){
            prime[re++]=i;
            while(tmp%i==0)tmp/=i;
        }
        if(tmp==1)break;
    }
    if(tmp>1)prime[re++]=tmp;
    for(register int i=1; i<=1000; i++)fac[i]=fac[i-1]*(LL)i%mod;
    for(register int i=1; i<=1000; i++)facinv[i]=power(fac[i], mod-2);
    while(q--){
        scanf("%lld %lld", &a, &b);
        LL g=gcd(a, b), ans=1;
        int sum1=0, sum2=0;
        for(int i=0; i<re; i++){
            int numa=0, numb=0, num=0;
            while(a%prime[i]==0){
                numa++;
                a/=prime[i];
            }
            while(b%prime[i]==0){
                numb++;
                b/=prime[i];
            }
            while(g%prime[i]==0){
                num++;
                g/=prime[i];
            }
            ans*=facinv[numa-num];
            ans%=mod;
            sum1+=numa-num;
            ans*=facinv[numb-num];
            ans%=mod;
            sum2+=numb-num;
        }
        ans*=fac[sum1];
        ans%=mod;
        ans*=fac[sum2];
        ans%=mod;
        printf("%lld\n", ans);
    }
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortvec(x) sort(all(x))
#define compress(x) x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL mod=998244353;
LL fac[1010];
LL n, a, b;
LL gcd(LL a, LL b){return b?gcd(b, a%b):a;}
LL power(LL a, LL b){
    if(!b)return 1;
    LL ret=power(a, b/2);
    if(b%2)return ret*ret%mod*a%mod;
    return ret*ret%mod;
}
int q;
bool ch[35000000];
vector<LL> prime;
int main(){
    scanf("%lld %d", &n, &q);
    fac[0]=1;
    LL tmp=n;
    for(register LL i=2; i<=tmp; i++){
        if(ch[(int)i])continue;
        if(tmp%i==0){
            prime.pb(i);
            while(tmp%i==0)tmp/=i;
        }
        if(tmp==1)break;
        for(LL j=2*i; j*j<=n; j+=i)ch[(int)j]=true;
    }
    if(tmp>1)prime.pb(tmp);
    for(int i=1; i<=1000; i++)fac[i]=fac[i-1]*(LL)i%mod;
    while(q--){
        scanf("%lld %lld", &a, &b);
        LL g=gcd(a, b);
        vector<int> vca, vcb, vcg;
        vca.resize(prime.size());
        vcb.resize(prime.size());
        vcg.resize(prime.size());
        for(int i=0; i<prime.size(); i++){
            while(a%prime[i]==0){
                vca[i]++;
                a/=prime[i];
            }
        }
        for(int i=0; i<prime.size(); i++){
            while(b%prime[i]==0){
                vcb[i]++;
                b/=prime[i];
            }
        }
        for(int i=0; i<prime.size(); i++){
            while(g%prime[i]==0){
                vcg[i]++;
                g/=prime[i];
            }
        }
        LL ans=1;
        int sum1=0, sum2=0;
        for(int i=0; i<prime.size(); i++){
            ans*=power(fac[vca[i]-vcg[i]], mod-2);
            ans%=mod;
            sum1+=vca[i]-vcg[i];
            ans*=power(fac[vcb[i]-vcg[i]], mod-2);
            ans%=mod;
            sum2+=vcb[i]-vcg[i];
        }
        ans*=fac[sum1];
        ans%=mod;
        ans*=fac[sum2];
        ans%=mod;
        printf("%lld\n", ans);
    }
}


#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long LL;
const LL mod=998244353;
LL fac[1010], n, a, b;
LL gcd(LL a, LL b){return b?gcd(b, a%b):a;}
LL power(LL a, LL b){
    if(!b)return 1ll;
    LL ret=power(a, b/2);
    if(b%2)return ret*ret%mod*a%mod;
    return ret*ret%mod;
}
int q;
bool ch[35000000];
LL prime[100010], facinv[1010];
int re;
int main(){
    scanf("%lld %d", &n, &q);
    fac[0]=1;
    LL tmp=n;
    for(register LL i=2; i*i<=n; i++){
        if(tmp%i==0){
            prime[re++]=i;
            while(tmp%i==0)tmp/=i;
        }
        if(tmp==1)break;
    }
    if(tmp>1)prime[re++]=tmp;
    for(register int i=1; i<=1000; i++)fac[i]=fac[i-1]*(LL)i%mod;
    for(register int i=1; i<=1000; i++)facinv[i]=power(fac[i], mod-2);
    while(q--){
        scanf("%lld %lld", &a, &b);
        LL g=gcd(a, b), ans=1;
        int sum1=0, sum2=0;
        for(int i=0; i<re; i++){
            int numa=0, numb=0, num=0;
            while(a%prime[i]==0){
                numa++;
                a/=prime[i];
            }
            while(b%prime[i]==0){
                numb++;
                b/=prime[i];
            }
            while(g%prime[i]==0){
                num++;
                g/=prime[i];
            }
            ans*=facinv[numa-num];
            ans%=mod;
            sum1+=numa-num;
            ans*=facinv[numa-num];
            ans%=mod;
            sum2+=numb-num;
        }
        ans*=fac[sum1];
        ans%=mod;
        ans*=fac[sum2];
        ans%=mod;
        printf("%lld\n", ans);
    }
}


#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long LL;
const LL mod=998244353;
LL fac[1010], n, a, b;
LL gcd(LL a, LL b){return b?gcd(b, a%b):a;}
LL power(LL a, LL b){
    if(!b)return 1ll;
    LL ret=power(a, b/2);
    if(b%2)return ret*ret%mod*a%mod;
    return ret*ret%mod;
}
int q;
bool ch[35000000];
LL prime[100010], facinv[1010];
int re;
int main(){
    scanf("%lld %d", &n, &q);
    fac[0]=1;
    LL tmp=n;
    for(register LL i=2; i*i<=n; i++){
        if(tmp%i==0){
            prime[re++]=i;
            while(tmp%i==0)tmp/=i;
        }
        if(tmp==1)break;
    }
    if(tmp>1)prime[re++]=tmp;
    for(register int i=1; i<=1000; i++)fac[i]=fac[i-1]*(LL)i%mod;
    for(register int i=1; i<=1000; i++)facinv[i]=power(fac[i], mod-2);
    while(q--){
        scanf("%lld %lld", &a, &b);
        LL g=gcd(a, b), ans=1;
        int sum1=0, sum2=0;
        for(int i=0; i<re; i++){
            int numa=0, numb=0, num=0;
            while(a%prime[i]==0){
                numa++;
                a/=prime[i];
            }
            while(b%prime[i]==0){
                numb++;
                b/=prime[i];
            }
            while(g%prime[i]==0){
                num++;
                g/=prime[i];
            }
            ans*=facinv[numa-num];
            ans%=mod;
            sum1+=numa-num;
            ans*=facinv[numb-num];
            ans%=mod;
            sum2+=numb-num;
        }
        ans*=fac[sum1];
        ans%=mod;
        ans*=fac[sum2];
        ans%=mod;
        printf("%lld\n", ans);
    }
}


#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long LL;
const LL mod=998244353;
LL fac[1010], n, a, b;
LL gcd(LL a, LL b){return b?gcd(b, a%b):a;}
LL power(LL a, LL b){
    if(!b)return 1ll;
    LL ret=power(a, b/2);
    if(b%2)return ret*ret%mod*a%mod;
    return ret*ret%mod;
}
int q;
bool ch[35000000];
LL prime[100010];
int re;
int main(){
    scanf("%lld %d", &n, &q);
    fac[0]=1;
    LL tmp=n;
    for(register LL i=2; i*i<=n; i++){
        if(tmp%i==0){
            prime[re++]=i;
            while(tmp%i==0)tmp/=i;
        }
        if(tmp==1)break;
    }
    if(tmp>1)prime[re++]=tmp;
    for(register int i=1; i<=1000; i++)fac[i]=fac[i-1]*(LL)i%mod;
    while(q--){
        scanf("%lld %lld", &a, &b);
        LL g=gcd(a, b), ans=1;
        int sum1=0, sum2=0;
        for(int i=0; i<re; i++){
            int numa=0, numb=0, num=0;
            while(a%prime[i]==0){
                numa++;
                a/=prime[i];
            }
            while(b%prime[i]==0){
                numb++;
                b/=prime[i];
            }
            while(g%prime[i]==0){
                num++;
                g/=prime[i];
            }
            ans*=power(fac[numa-num], mod-2);
            ans%=mod;
            sum1+=numa-num;
            ans*=power(fac[numb-num], mod-2);
            ans%=mod;
            sum2+=numb-num;
        }
        ans*=fac[sum1];
        ans%=mod;
        ans*=fac[sum2];
        ans%=mod;
        printf("%lld\n", ans);
    }
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortvec(x) sort(all(x))
#define compress(x) x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL mod=998244353;
LL fac[1010];
LL n, a, b;
LL gcd(LL a, LL b){return b?gcd(b, a%b):a;}
LL power(LL a, LL b){
    if(!b)return 1;
    LL ret=power(a, b/2);
    if(b%2)return ret*ret%mod*a%mod;
    return ret*ret%mod;
}
int q;
bool ch[35000000];
LL prime[100010];
int re;
int main(){
    scanf("%lld %d", &n, &q);
    fac[0]=1;
    LL tmp=n;
    for(register LL i=2; i*i<=n; i++){
        if(tmp%i==0){
            prime[re++]=i;
            while(tmp%i==0)tmp/=i;
        }
        if(tmp==1)break;
    }
    if(tmp>1)prime[re++]=tmp;
    for(int i=1; i<=1000; i++)fac[i]=fac[i-1]*(LL)i%mod;
    while(q--){
        scanf("%lld %lld", &a, &b);
        LL g=gcd(a, b);
        vector<int> vca, vcb, vcg;
        vca.resize(re);
        vcb.resize(re);
        vcg.resize(re);
        for(int i=0; i<re; i++){
            while(a%prime[i]==0){
                vca[i]++;
                a/=prime[i];
            }
        }
        for(int i=0; i<re; i++){
            while(b%prime[i]==0){
                vcb[i]++;
                b/=prime[i];
            }
        }
        for(int i=0; i<re; i++){
            while(g%prime[i]==0){
                vcg[i]++;
                g/=prime[i];
            }
        }
        LL ans=1;
        int sum1=0, sum2=0;
        for(int i=0; i<re; i++){
            ans*=power(fac[vca[i]-vcg[i]], mod-2);
            ans%=mod;
            sum1+=vca[i]-vcg[i];
            ans*=power(fac[vcb[i]-vcg[i]], mod-2);
            ans%=mod;
            sum2+=vcb[i]-vcg[i];
        }
        ans*=fac[sum1];
        ans%=mod;
        ans*=fac[sum2];
        ans%=mod;
        printf("%lld\n", ans);
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <cassert>
#include <unordered_map>
#define int long long

using namespace std;

typedef pair<int, int> pa;
typedef long long ll;
typedef long double ld;

struct go {
    int a, b;
};

const int mod = 998244353;

unordered_map<int, int> ans;
unordered_map<int, vector<int>> sz;

void calc(int d) {
    int x = d, val = 2;
    while (x != 1 && val <= sqrt(d)) {
        while (x % val == 0) {
            x /= val;
            if (sz[d].size() == 0 || sz[d].back() != val)
                sz[d].push_back(val);
        }
        ++val;
    }
    if (x > 1)
        sz[d].push_back(x);
}

int solve(int d) {
    if (d == 1) return 1;

    int A = 0;
    if (ans[d]) return ans[d];
    if (sz.count(d) == 0) calc(d);

    for (int vals : sz[d]) {
        A += solve(d / vals);
    }
    ans[d] = A % mod;
    return A;
}

int gcd(int u, int v) {
    while (u) {
        int c = v % u;
        v = u;
        u = c;
    }
    return v;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int d;
    cin >> d;
    int q;
    cin >> q;
    while (q--) {
        int u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);

        if (v % u == 0) {
            cout << solve(v / u);
        } else {
            int gc;
            int G = gcd(u, v);

            cout << solve(u / G) * solve(v / G) % mod;
        }
        cout << '\n';
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <cassert>
#define int long long

using namespace std;

typedef pair<int, int> pa;
typedef long long ll;
typedef long double ld;

struct go {
    int a, b;
};

const int mod = 998244353;

map<int, int> ans;
map<int, vector<int>> sz;

void calc(int d) {
    int x = d, val = 2;
    while (x != 1 && val <= sqrt(d)) {
        while (x % val == 0) {
            x /= val;
            if (sz[d].size() == 0 || sz[d].back() != val)
                sz[d].push_back(val);
        }
        ++val;
    }
    if (x > 1)
        sz[d].push_back(x);
}

int solve(int u, int v) {
    if (u == v) return 1;

    int d = v / u, A = 0;
    if (ans[d]) return ans[d];
    if (sz.count(d) == 0) calc(d);

    for (int vals : sz[d]) {
        A += solve(vals, d);
        A %= mod;
    }
    ans[d] = A;
    return A;
}

int gcd(int u, int v) {
    while (u) {
        int c = v % u;
        v = u;
        u = c;
    }
    return v;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int d;
    cin >> d;
    int q;
    cin >> q;
    while (q--) {
        int u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);

        if (v % u == 0) {
            cout << solve(u, v);
        } else {
            int gc;
            int G = gcd(u, v);

            cout << solve(G, u) * solve(G, v) % mod;
        }
        cout << '\n';
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <cassert>
#include <unordered_map>
#define int long long

using namespace std;

typedef pair<int, int> pa;
typedef long long ll;
typedef long double ld;

struct go {
    int a, b;
};

const int mod = 998244353;

map<int, int> ans;
map<int, vector<int>> sz;

void calc(int d) {
    int x = d, val = 2;
    while (x != 1 && val <= sqrt(d)) {
        while (x % val == 0) {
            x /= val;
            if (sz[d].size() == 0 || sz[d].back() != val)
                sz[d].push_back(val);
        }
        ++val;
    }
    if (x > 1)
        sz[d].push_back(x);
}

int solve(int d) {
    if (d == 1) return 1;

    int A = 0;
    if (ans[d]) return ans[d];
    if (sz.count(d) == 0) calc(d);

    for (int vals : sz[d]) {
        A += solve(d / vals);
    }
    A %= mod;
    ans[d] = A % mod;
    return A;
}

int gcd(int u, int v) {
    while (u) {
        int c = v % u;
        v = u;
        u = c;
    }
    return v;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int d;
    cin >> d;
    int q;
    cin >> q;
    while (q--) {
        int u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);

        if (v % u == 0) {
            cout << solve(v / u);
        } else {
            int gc;
            int G = gcd(u, v);

            cout << solve(u / G) * solve(v / G) % mod;
        }
        cout << '\n';
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <cassert>
#include <unordered_map>
#define int long long

using namespace std;

typedef pair<int, int> pa;
typedef long long ll;
typedef long double ld;

struct go {
    int a, b;
};

const int mod = 998244353;

unordered_map<int, int> ans;
vector<int> All;

void calc(int d) {
    int x = d, val = 2;
    while (x != 1 && val <= sqrt(d)) {
        while (x % val == 0) {
            x /= val;
            if (All.size() == 0 || All.back() != val)
                All.push_back(val);
        }
        ++val;
    }
    if (x > 1)
        All.push_back(x);
}

int solve(int d) {
    if (d == 1) return 1;

    int A = 0;
    if (ans[d]) return ans[d];

    for (int vals : All) {
        if (d % vals == 0)
            A += solve(d / vals);
    }
    A %= mod;
    ans[d] = A % mod;
    return A;
}

int gcd(int u, int v) {
    while (u) {
        int c = v % u;
        v = u;
        u = c;
    }
    return v;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int d;
    cin >> d;
    calc(d);
    int q;
    cin >> q;
    while (q--) {
        int u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);

        if (v % u == 0) {
            cout << solve(v / u);
        } else {
            int gc;
            int G = gcd(u, v);

            cout << solve(u / G) * solve(v / G) % mod;
        }
        cout << '\n';
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <cassert>
#include <unordered_map>
#define int long long

using namespace std;

typedef pair<int, int> pa;
typedef long long ll;
typedef long double ld;

struct go {
    int a, b;
};

const int mod = 998244353;

unordered_map<int, int> ans;
unordered_map<int, vector<int>> sz;

void calc(int d) {
    int x = d, val = 2;
    while (x != 1 && val <= sqrt(d)) {
        while (x % val == 0) {
            x /= val;
            if (sz[d].size() == 0 || sz[d].back() != val)
                sz[d].push_back(val);
        }
        ++val;
    }
    if (x > 1)
        sz[d].push_back(x);
}

int solve(int d) {
    if (d == 1) return 1;

    int A = 0;
    if (ans[d]) return ans[d];
    if (sz.count(d) == 0) calc(d);

    for (int vals : sz[d]) {
        A += solve(d / vals);
        A %= mod;
    }
    ans[d] = A % mod;
    return A;
}

int gcd(int u, int v) {
    while (u) {
        int c = v % u;
        v = u;
        u = c;
    }
    return v;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int d;
    cin >> d;
    int q;
    cin >> q;
    while (q--) {
        int u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);

        if (v % u == 0) {
            cout << solve(v / u);
        } else {
            int gc;
            int G = gcd(u, v);

            cout << solve(u / G) * solve(v / G) % mod;
        }
        cout << '\n';
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <cassert>
#define int long long

using namespace std;

typedef pair<int, int> pa;
typedef long long ll;
typedef long double ld;

struct go {
    int a, b;
};

const int mod = 998244353;

map<pa, int> ans;
map<int, vector<int>> sz;

void calc(int d) {
    int x = d, val = 2;
    while (x != 1 && val <= sqrt(d)) {
        while (x % val == 0) {
            x /= val;
            if (sz[d].size() == 0 || sz[d].back() != val)
                sz[d].push_back(val);
        }
        ++val;
    }
    if (x > 1)
        sz[d].push_back(x);
}

int solve(int u, int v) {
    if (u == v) return 1;
    if (ans.count({u, v})) return ans[{u, v}];

    int d = v / u, A = 0;
    if (sz.count(d) == 0) calc(d);

    for (int vals : sz[d]) {
        A += solve(u * vals, v);
        A %= mod;
    }
    ans[{u, v}] = A;
    return A;
}

int gcd(int u, int v) {
    while (u) {
        int c = v % u;
        v = u;
        u = c;
    }
    return v;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int d;
    cin >> d;
    int q;
    cin >> q;
    while (q--) {
        int u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);

        if (v % u == 0) {
            cout << solve(u, v);
        } else {
            int gc;
            int G = gcd(u, v);

            cout << solve(G, u) * solve(G, v) % mod;
        }
        cout << '\n';
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <cassert>
#include <unordered_map>
#define int long long

using namespace std;

typedef pair<int, int> pa;
typedef long long ll;
typedef long double ld;

struct go {
    int a, b;
};

const int mod = 998244353;

unordered_map<int, int> ans;
unordered_map<int, vector<int>> sz;

void calc(int d) {
    int x = d, val = 2;
    while (x != 1 && val <= sqrt(d)) {
        while (x % val == 0) {
            x /= val;
            if (sz[d].size() == 0 || sz[d].back() != val)
                sz[d].push_back(val);
        }
        ++val;
    }
    if (x > 1)
        sz[d].push_back(x);
}

int solve(int d) {
    if (d == 1) return 1;

    int A = 0;
    if (ans[d]) return ans[d];
    if (sz.count(d) == 0) calc(d);

    for (int vals : sz[d]) {
        A += solve(d / vals);
    }
    ans[d] = A % mod;
    return A;
}

int gcd(int u, int v) {
    while (u) {
        int c = v % u;
        v = u;
        u = c;
    }
    return v;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int d;
    cin >> d;
    int q;
    cin >> q;
    while (q--) {
        int u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);

        if (v % u == 0) {
            cout << solve(u, v);
        } else {
            int gc;
            int G = gcd(u, v);

            cout << solve(u / G) * solve(v / G) % mod;
        }
        cout << '\n';
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <cassert>
#include <unordered_map>
#define int long long

using namespace std;

typedef pair<int, int> pa;
typedef long long ll;
typedef long double ld;

struct go {
    int a, b;
};

const int mod = 998244353;

unordered_map<int, int> ans;
unordered_map<int, vector<int>> sz;

void calc(int d) {
    int x = d, val = 2;
    while (x != 1 && val <= sqrt(d)) {
        while (x % val == 0) {
            x /= val;
            if (sz[d].size() == 0 || sz[d].back() != val)
                sz[d].push_back(val);
        }
        ++val;
    }
    if (x > 1)
        sz[d].push_back(x);
}

int solve(int d) {
    if (d == 1) return 1;

    int A = 0;
    if (ans[d]) return ans[d];
    if (sz.count(d) == 0) calc(d);

    for (int vals : sz[d]) {
        A += solve(d / vals);
    }
    A %= mod;
    ans[d] = A % mod;
    return A;
}

int gcd(int u, int v) {
    while (u) {
        int c = v % u;
        v = u;
        u = c;
    }
    return v;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int d;
    cin >> d;
    int q;
    cin >> q;
    while (q--) {
        int u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);

        if (v % u == 0) {
            cout << solve(v / u);
        } else {
            int gc;
            int G = gcd(u, v);

            cout << solve(u / G) * solve(v / G) % mod;
        }
        cout << '\n';
    }
}


#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <cmath>
#include <cassert>
#include <unordered_map>
#define int long long

using namespace std;

typedef pair<int, int> pa;
typedef long long ll;
typedef long double ld;

struct go {
    int a, b;
};

const int mod = 998244353;

unordered_map<int, int> ans;
unordered_map<int, vector<int>> sz;

void calc(int d) {
    int x = d, val = 2;
    while (x != 1 && val <= sqrt(d)) {
        while (x % val == 0) {
            x /= val;
            if (sz[d].size() == 0 || sz[d].back() != val)
                sz[d].push_back(val);
        }
        ++val;
    }
    if (x > 1)
        sz[d].push_back(x);
}

int solve(int u, int v) {
    if (u == v) return 1;

    int d = v / u, A = 0;
    if (ans[d]) return ans[d];
    if (sz.count(d) == 0) calc(d);

    for (int vals : sz[d]) {
        A += solve(vals, d);
        A %= mod;
    }
    ans[d] = A;
    return A;
}

int gcd(int u, int v) {
    while (u) {
        int c = v % u;
        v = u;
        u = c;
    }
    return v;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int d;
    cin >> d;
    int q;
    cin >> q;
    while (q--) {
        int u, v;
        cin >> u >> v;
        if (u > v) swap(u, v);

        if (v % u == 0) {
            cout << solve(u, v);
        } else {
            int gc;
            int G = gcd(u, v);

            cout << solve(G, u) * solve(G, v) % mod;
        }
        cout << '\n';
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define xx first
#define yy second
const int BS=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e18+10;
ll mod=  998244353;
const ll mxn= 3e5+20;
const int N=2.5*1e7+10;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n,k,m,q,x,y,p;
ll fast_exp(ll base, ll exp) {
    ll res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       exp/=2;
    }
    return res%mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>x;
    vector<ll> v;
    for(ll i=2;i*i<=x;i++){
        if(x%i==0) v.pb(i);
        while(x%i==0) x/=i;
    }
    if(x>1) v.pb(x);
    vector<ll> fact, rfact;
    fact.pb(1), rfact.pb(1);
    for(int i=1;i<100;i++) fact.pb(i*fact[i-1]), fact[i]%=mod, rfact.pb(fast_exp(fact[i],mod-2));;

    cin>>q;
    while(q--){
        cin>>x>>y;
        ll g=__gcd(x,y);
        ll t=x/g, u=y/g;
        ll ways=1, cnt1=0, cnt2=0;
        vector<int> rep1, rep2;
        for(auto k: v){
            int cur=0;
            while(t%k==0) cnt1++, t/=k, cur++;
            if(cur) rep1.pb(cur);
            cur=0;
            while(u%k==0) cnt2++, u/=k, cur++;
            if(cur) rep2.pb(cur);
        }
        ways=fact[cnt1];
        for(auto k: rep1) ways*=rfact[k], ways%=mod;
        ways*=fact[cnt2], ways%=mod;
        for(auto k: rep2) ways*=rfact[k], ways%=mod;
        cout<<(ways+mod)%mod<<'\n';
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define xx first
#define yy second
const int BS=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e18+10;
ll mod=  998244353;
const ll mxn= 3e5+20;
const int N=2.5*1e7+10;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n,k,m,q,x,y,p;
ll fast_exp(ll base, ll exp) {
    ll res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       exp/=2;
    }
    return res%mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>x;
    vector<ll> v;
    for(int i=2;i*i<=x;i++){
        if(x%i==0) v.pb(i);
        while(x%i==0) x/=i;
    }
    if(x>1) v.pb(x);
    vector<ll> fact, rfact;
    fact.pb(1), rfact.pb(1);
    for(int i=1;i<100;i++) fact.pb(i*fact[i-1]), fact[i]%=mod, rfact.pb(fast_exp(fact[i],mod-2));;

    cin>>q;
    while(q--){
        cin>>x>>y;
        ll g=__gcd(x,y);
        ll t=x/g, u=y/g;
        ll ways=1, cnt1=0, cnt2=0;
        vector<int> rep1, rep2;
        for(auto k: v){
            int cur=0;
            while(t%k==0) cnt1++, t/=k, cur++;
            if(cur) rep1.pb(cur);
            cur=0;
            while(u%k==0) cnt2++, u/=k, cur++;
            if(cur) rep2.pb(cur);
        }
        ways=fact[cnt1];
        for(auto k: rep1) ways*=rfact[k], ways%=mod;
        ways*=fact[cnt2], ways%=mod;
        for(auto k: rep2) ways*=rfact[k], ways%=mod;
        cout<<(ways+mod)%mod<<'\n';
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define xx first
#define yy second
const int BS=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e18+10;
ll mod=  998244353;
const ll mxn= 3e5+20;
const int N=2.5*1e7+10;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n,k,m,q,x,y,p;
ll fast_exp(ll base, ll exp) {
    ll res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       exp/=2;
    }
    return res%mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>x;
    vector<ll> v;
    for(int i=2;i*i<=x;i++){
        if(x%i==0) v.pb(i);
        while(x%i==0) x/=i;
    }
    if(x>1) v.pb(x);
    vector<ll> fact;
    fact.pb(1);
    for(int i=1;i<100;i++) fact.pb(i*fact[i-1]), fact[i]%=mod;

    cin>>q;
    while(q--){
        cin>>x>>y;
        ll g=__gcd(x,y);
        ll t=x/g, u=y/g;
        ll ways=1, cnt1=0, cnt2=0;
        vector<int> rep1, rep2;
        for(auto k: v){
            int cur=0;
            while(t%k==0) cnt1++, t/=k, cur++;
            if(cur) rep1.pb(cur);
            cur=0;
            while(u%k==0) cnt2++, u/=k, cur++;
            if(cur) rep2.pb(cur);
        }
        ways=fact[cnt1];
        for(auto k: rep1) ways*=fast_exp(fact[k],mod-2), ways%=mod;
        ways*=fact[cnt2], ways%=mod;
        for(auto k: rep2) ways*=fast_exp(fact[k],mod-2), ways%=mod;
        cout<<(ways+mod)%mod<<'\n';
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define xx first
#define yy second
const int BS=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e18+10;
ll mod=  998244353;
const ll mxn= 3e5+20;
const int N=2.5*1e7+10;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n,k,m,q,x,y,p;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>x;
    vector<ll> v;
    for(ll i=2;i*i<=x;i++){
        if(x%i==0) v.pb(i);
        while(x%i==0) x/=i;
    }
    if(x>1) v.pb(i);
    vector<ll> fact;
    fact.pb(1);
    for(int i=1;i<100;i++) fact.pb(i*fact[i-1]), fact[i]%=mod;

    cin>>q;
    while(q--){
        int x,y;
        cin>>x>>y;
        ll g=__gcd(x,y);
        ll t=x/g, u=y/g;
        ll ways=1, cnt1=0, cnt2=0;
        vector<int> rep1, rep2;
        for(auto k: v){
            int cur=0;
            while(t%k==0) cnt1++, t/=k, cur++;
            if(cur) rep1.pb(cur);
            cur=0;
            while(u%k==0) cnt2++, u/=k, cur++;
            if(cur) rep2.pb(cur);
        }
        ways=fact[cnt1];
        for(auto k: rep1) ways/=fact[k];
        ways*=fact[cnt2], ways%=mod;
        for(auto k: rep2) ways/=fact[k];
        cout<<(ways+mod)%mod<<'\n';
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define xx first
#define yy second
const int BS=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e18+10;
ll mod=  998244353;
const ll mxn= 3e5+20;
const int N=2.5*1e7+10;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n,k,m,q,x,y,p;
ll fast_exp(ll base, ll exp) {
    ll res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       exp/=2;
    }
    return res%mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>x;
    vector<int> v;
    for(int i=2;i<=x;i++){
        if(x%i==0) v.pb(i);
        while(x%i==0) x/=i;
    }
    vector<ll> fact;
    fact.pb(1);
    for(int i=1;i<100;i++) fact.pb(i*fact[i-1]), fact[i]%=mod;

    cin>>q;
    while(q--){
        cin>>x>>y;
        ll g=__gcd(x,y);
        ll t=x/g, u=y/g;
        ll ways=1, cnt1=0, cnt2=0;
        vector<int> rep1, rep2;
        for(auto k: v){
            int cur=0;
            while(t%k==0) cnt1++, t/=k, cur++;
            if(cur) rep1.pb(cur);
            cur=0;
            while(u%k==0) cnt2++, u/=k, cur++;
            if(cur) rep2.pb(cur);
        }
        ways=fact[cnt1];
        for(auto k: rep1) ways*=fast_exp(fact[k],mod-2), ways%=mod;
        ways*=fact[cnt2], ways%=mod;
        for(auto k: rep2) ways*=fast_exp(fact[k],mod-2), ways%=mod;
        cout<<(ways+mod)%mod<<'\n';
    }
}


#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define xx first
#define yy second
const int BS=500;
using namespace std;
using namespace __gnu_pbds;
#define be begin()
#define rb rbegin()
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define nod int node,int l,int r
#define lson node*2,l,(l+r)/2
#define rson node*2+1,(l+r)/2+1,r
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> rbTree;
const ll inf= 1e18+10;
ll mod=  998244353;
const ll mxn= 3e5+20;
const int N=2.5*1e7+10;
const double pi=3.14159;
#define mp make_pair
#define mp3(a,b,c) mp(a,mp(b,c))
typedef pair<int,int> pii;
typedef pair<int,pair<int,int> > piii;
typedef pair<int,pair<int,pair<int,int>>> piiii;
typedef pair<ll, int> pli;
typedef pair<ll,ll> pll;
int dx[]={0,1,0,-1,1,-1,1,-1};
int dy[]={1,0,-1,0,-1,1,1,-1};
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll n,k,m,q,x,y,p;
ll fast_exp(ll base, ll exp) {
    ll res=1;
    while(exp>0) {
       if(exp%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       exp/=2;
    }
    return res%mod;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cin>>x;
    vector<int> v;
    for(int i=2;i*i<=x;i++){
        if(x%i==0) v.pb(i);
        while(x%i==0) x/=i;
    }
    if(x>1) v.pb(x);
    vector<ll> fact;
    fact.pb(1);
    for(int i=1;i<100;i++) fact.pb(i*fact[i-1]), fact[i]%=mod;

    cin>>q;
    while(q--){
        cin>>x>>y;
        ll g=__gcd(x,y);
        ll t=x/g, u=y/g;
        ll ways=1, cnt1=0, cnt2=0;
        vector<int> rep1, rep2;
        for(auto k: v){
            int cur=0;
            while(t%k==0) cnt1++, t/=k, cur++;
            if(cur) rep1.pb(cur);
            cur=0;
            while(u%k==0) cnt2++, u/=k, cur++;
            if(cur) rep2.pb(cur);
        }
        ways=fact[cnt1];
        for(auto k: rep1) ways*=fast_exp(fact[k],mod-2), ways%=mod;
        ways*=fact[cnt2], ways%=mod;
        for(auto k: rep2) ways*=fast_exp(fact[k],mod-2), ways%=mod;
        cout<<(ways+mod)%mod<<'\n';
    }
}


#include <bits/stdc++.h>
using namespace std;
#define N 40000000
#define maxn (N + 10)
typedef long long ll;
const ll mod = 998244353;
ll a[100],c[100][100],an,sn;
unordered_map<ll,ll>mp;
void init(){
	c[0][0] = 1;
	for(int i = 1;i <= 80;i++){
		c[i][0] = 1;
		for(int j = 1;j <= i;j++){
			c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
			c[i][j] %= mod;
		}
	}
	/*for(int i = 1;i <= 10;i++){
		for(int j = 0;j <= i;j++){
			printf("%lld ",c[i][j]);
		}
		printf("\n");
	}*/
}
inline ll gcd(ll x,ll y){
	return y == 0 ? x : gcd(y,x % y);
}
inline ll dive(ll x){
	an = 0;sn = 0;
	memset(a,0,sizeof(a));
	for(int i = 2;i * i <= x;i++){
		if(x % i == 0){
			an++;
			while(x % i == 0){
				a[an]++;x /= i;
			}
			sn += a[an];
		}
	}
	if(x > 1){
		a[++an] = 1;sn++;
	}
	ll ans = 1;
	for(int i = 1;i <= an;i++){
		ans *= c[sn][a[i]];ans %= mod;sn -= a[i];
	}
	return ans;
}
int main(){
	init();
	ll d;scanf("%lld",&d);
	for(ll i = 1;i * i <= d;i++){
		if(d % i == 0){
			mp[i] = dive(i);
			mp[d / i] = dive(d / i);
		}
	}
	int q;scanf("%d",&q);
	while(q--){
		ll u,v;scanf("%lld%lld",&u,&v);
		ll g = gcd(u,v);
		ll ans = mp[u / g] * mp[v / g];ans %= mod;
		printf("%lld\n",ans);
	}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define N 40000000
#define maxn (N + 10)
typedef long long ll;
const ll mod = 998244353;
ll a[100],c[100][100],an,sn;
unordered_map<ll,ll>mp;
void init(){
	c[0][0] = 1;
	for(int i = 1;i <= 80;i++){
		c[i][0] = 1;
		for(int j = 1;j <= i;j++){
			c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
			c[i][j] %= mod;
		}
	}
	/*for(int i = 1;i <= 10;i++){
		for(int j = 0;j <= i;j++){
			printf("%lld ",c[i][j]);
		}
		printf("\n");
	}*/
}
ll gcd(ll x,ll y){
	return y == 0 ? x : gcd(y,x % y);
}
ll dive(ll x){
	an = 0;sn = 0;
	memset(a,0,sizeof(a));
	for(int i = 2;i * i <= x;i++){
		if(x % i == 0){
			an++;
			while(x % i == 0){
				a[an]++;x /= i;
			}
			sn += a[an];
		}
	}
	if(x > 1){
		a[++an] = 1;sn++;
	}
	ll ans = 1;
	for(int i = 1;i <= an;i++){
		ans *= c[sn][a[i]];ans %= mod;sn -= a[i];
	}
	return ans;
}
int main(){
	init();
	ll d;scanf("%lld",&d);
	for(ll i = 1;i * i <= d;i++){
		if(d % i == 0){
			mp[i] = dive(i);
			mp[d / i] = dive(d / i);
		}
	}
	int q;scanf("%d",&q);
	while(q--){
		ll u,v;scanf("%lld%lld",&u,&v);
		ll g = gcd(u,v);
		ll ans = mp[u / g] * mp[v / g];ans %= mod;
		printf("%lld\n",ans);
	}
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define N 40000000
#define maxn (N + 10)
typedef long long ll;
const ll mod = 998244353;
ll prime[maxn],pn;
bool jud[maxn];
ll a[100],c[100][100],an,sn;
void init(){
	pn = 0;
	for(ll i = 2;i <= N;i++){
		if(!jud[i])prime[++pn] = i;
		for(int j = 1;j <= pn;j++){
			ll cnt = prime[j] * i;
			if(cnt > N)break;
			jud[cnt] = true;
			if(i % prime[j] == 0)break;
		}
	}
	c[0][0] = 1;
	for(int i = 1;i <= 80;i++){
		c[i][0] = 1;
		for(int j = 1;j <= i;j++){
			c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
			c[i][j] %= mod;
		}
	}
	/*for(int i = 1;i <= 10;i++){
		for(int j = 0;j <= i;j++){
			printf("%lld ",c[i][j]);
		}
		printf("\n");
	}*/
}
ll gcd(ll x,ll y){
	return y == 0 ? x : gcd(y,x % y);
}
void dive(ll x){
	an = 0;sn = 0;
	memset(a,0,sizeof(a));
	for(int i = 1;i <= pn && prime[i] <= x;i++){
		if(x % prime[i] == 0){
			an++;
			while(x % prime[i] == 0){
				a[an]++;x /= prime[i];
			}
			sn += a[an];
		}
	}
	if(x > 1){
		a[++an] = 1;sn++;
	}
}
int main(){
	init();
	ll d;scanf("%lld",&d);
	int q;scanf("%d",&q);
	while(q--){
		ll u,v;scanf("%lld%lld",&u,&v);
		ll g = gcd(u,v);
		//printf("g = %lld\n",g);
		ll x1 = u / g,x2 = v / g;
		ll ans = 1;
		dive(x1);
		//printf("an1 = %lld sn1 = %lld\n",an,sn);
		for(int i = 1;i <= an;i++){
			ans *= c[sn][a[i]];ans %= mod;sn -= a[i];
		}
		dive(x2);
		//printf("an2 = %lld sn2 = %lld\n",an,sn);
		for(int i = 1;i <= an;i++){
			ans *= c[sn][a[i]];ans %= mod;sn -= a[i];
		}
		printf("%lld\n",ans);
	}

    return 0;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    vector <int> a,b,c;
    for (int i=1;i<=x;i++){
        int so;
        cin>>so;
        a.push_back(so);
    }
    for (int i=1;i<=y;i++){
        int so;
        cin>>so;
        b.push_back(so);
    }
    for (int i=1;i<=z;i++){
        int so;
        cin>>so;
        c.push_back(so);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    long long ans=0;
    int i,j,k;
    i=a.size()-1;j=b.size()-1;k=c.size()-1;

    while ((i>=0&&j>=0)||(i>=0&&k>=0)||(j>=0&&k>=0)){
    int max1,max2;
    if (a[i]>b[j]&&a[i]>c[k]){
        max1=a[i];
        i--;
        if (b[j]>c[k]){
            max2=b[j];
            j--;
        }
        else{
            max2=c[k];
            k--;
        }
    }
    else{
        if (a[i]<b[j]&&b[j]>c[k]){
            max1=b[j];
            j--;
            if (a[i]>c[k]){
                max2=a[i];
                i--;
            }
            else{
                max2=c[k];
                k--;
            }
        }
        else{
            max1=c[k];
            k--;
            if (a[i]>b[j]){
                max2=a[i];
                i--;
            }
            else{
                max2=b[j];
                j--;
            }
        }
    }
    ans+=max1*max2;
    }
    cout<<ans;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;

int ans=0;
long long dp[205][205][205];
vector <int> a,b,c;
bool cmp(int a,int b){
    return (a>b);
}

int dp1(int x,int y,int z){
    if ((x>=a.size()&&y>=b.size())||(x>=a.size()&&z>=c.size())||(y>=b.size()&&z>=c.size())) return 0;
    int S=0;
    if (dp[x][y][z]!=-1) return dp[x][y][z];
    if (x<a.size()&&y<b.size()){
        S=max(S,a[x]*b[y]+dp1(x+1,y+1,z));
    }
    if (x<a.size()&&z<c.size()){

        S=max(S,a[x]*c[z]+dp1(x+1,y,z+1));
    }
    if (z<c.size()&&y<b.size()){

        S=max(S,b[y]*c[z]+dp1(x,y+1,z+1));
    }
   ans=max(ans,S);
   return dp[x][y][z]=S;
}

int main()
{
    int x,y,z;
    cin>>x>>y>>z;

    a.resize(x);
    b.resize(y);
    c.resize(z);
    for (int i=0;i<x;i++)cin>>a[i];
    for (int i=0;i<y;i++)cin>>b[i];
    for (int i=0;i<z;i++)cin>>c[i];

    sort(a.begin(),a.end(),cmp);
    sort(b.begin(),b.end(),cmp);
    sort(c.begin(),c.end(),cmp);

    memset(dp,-1,sizeof(dp));
    dp1(0,0,0);
    cout<<ans;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;

int ans=0;
long long dp[201][201][201];

bool cmp(int a,int b){
    return (a>b);
}

int dp1(int x,int y,int z,vector <int> a,vector <int> b,vector<int> c){

    int S=0;
    if (dp[x][y][z]!=-1) return dp[x][y][z];
    if (x<a.size()&&y<b.size()){
        S=max(S,a[x]*b[y]+dp1(x+1,y+1,z,a,b,c));
    }
    if (x<a.size()&&z<c.size()){

        S=max(S,a[x]*c[z]+dp1(x+1,y,z+1,a,b,c));
    }
    if (z<c.size()&&y<b.size()){

        S=max(S,b[y]*c[z]+dp1(x,y+1,z+1,a,b,c));
    }
   ans=max(ans,S);
    return dp[x][y][z]=S;
}

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    vector <int> a,b,c;
    for (int i=1;i<=x;i++){
        int so;
        cin>>so;
        a.push_back(so);
    }
    for (int i=1;i<=y;i++){
        int so;
        cin>>so;
        b.push_back(so);
    }
    for (int i=1;i<=z;i++){
        int so;
        cin>>so;
        c.push_back(so);
    }
    sort(a.begin(),a.end(),cmp);
    sort(b.begin(),b.end(),cmp);
    sort(c.begin(),c.end(),cmp);

    memset(dp,-1,sizeof(dp));
    dp1(0,0,0,a,b,c);
    cout<<ans;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;

int ans=0;
long long dp[201][201][201];
int dp1(int x,int y,int z,vector <int> a,vector <int> b,vector<int> c){
    if ((x==-1&&y==-1)||(x==-1&&z==-1)||(z==-1&&y==-1)) return 0;
    int S=0;
    if (dp[x][y][z]!=-1) return dp[x][y][z];
    if (x>-1&&y>-1){
        S=max(S,a[x]*b[y]+dp1(x-1,y-1,z,a,b,c));
    }
    if (x>-1&&z>-1){
        S=max(S,a[x]*c[z]+dp1(x-1,y,z-1,a,b,c));
    }
    if (y>-1&&z>-1){
        S=max(S,b[y]*c[z]+dp1(x,y-1,z-1,a,b,c));
    }
    ans=max(ans,S);
    return dp[x][y][z]=S;
}

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    vector <int> a,b,c;
    for (int i=1;i<=x;i++){
        int so;
        cin>>so;
        a.push_back(so);
    }
    for (int i=1;i<=y;i++){
        int so;
        cin>>so;
        b.push_back(so);
    }
    for (int i=1;i<=z;i++){
        int so;
        cin>>so;
        c.push_back(so);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());

    memset(dp,-1,sizeof(dp));
    dp1(a.size()-1,b.size()-1,c.size()-1,a,b,c);
    cout<<ans;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;

int ans=0;
long long dp[201][201][201];

bool cmp(int a,int b){
    return (a>b);
}

int dp1(int x,int y,int z,vector <int> a,vector <int> b,vector<int> c){

    int S=0;
    //if (x!=-1&&y!=-1&&z!=-1) if (dp[x][y][z]!=-1) return dp[x][y][z];
    if (x<a.size()&&y<b.size()){

        S=max(S,a[x]*b[y]+dp1(x+1,y+1,z,a,b,c));
    }
    if (x<a.size()&&z<c.size()){

        S=max(S,a[x]*c[z]+dp1(x+1,y,z+1,a,b,c));
    }
    if (z<c.size()&&y<b.size()){

        S=max(S,b[y]*c[z]+dp1(x,y+1,z+1,a,b,c));
    }
   ans=max(ans,S);
    return S;
}

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    vector <int> a,b,c;
    for (int i=1;i<=x;i++){
        int so;
        cin>>so;
        a.push_back(so);
    }
    for (int i=1;i<=y;i++){
        int so;
        cin>>so;
        b.push_back(so);
    }
    for (int i=1;i<=z;i++){
        int so;
        cin>>so;
        c.push_back(so);
    }
    sort(a.begin(),a.end(),cmp);
    sort(b.begin(),b.end(),cmp);
    sort(c.begin(),c.end(),cmp);

    memset(dp,-1,sizeof(dp));
    dp1(0,0,0,a,b,c);
    cout<<ans;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;

int ans=0;
long long dp[201][201][201];

bool cmp(int a,int b){
    return (a>b);
}

int dp1(int x,int y,int z,vector <int> a,vector <int> b,vector<int> c){
    if ((x>=a.size()&&y>=b.size())||(x>=a.size()&&z>=c.size())||(y>=b.size()&&z>=c.size())) return 0;
    int S=0;
    if (dp[x][y][z]!=-1) return dp[x][y][z];
    if (x<a.size()&&y<b.size()){
        S=max(S,a[x]*b[y]+dp1(x+1,y+1,z,a,b,c));
    }
    if (x<a.size()&&z<c.size()){

        S=max(S,a[x]*c[z]+dp1(x+1,y,z+1,a,b,c));
    }
    if (z<c.size()&&y<b.size()){

        S=max(S,b[y]*c[z]+dp1(x,y+1,z+1,a,b,c));
    }
   ans=max(ans,S);
    return dp[x][y][z]=S;
}

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    vector <int> a,b,c;
    for (int i=1;i<=x;i++){
        int so;
        cin>>so;
        a.push_back(so);
    }
    for (int i=1;i<=y;i++){
        int so;
        cin>>so;
        b.push_back(so);
    }
    for (int i=1;i<=z;i++){
        int so;
        cin>>so;
        c.push_back(so);
    }
    sort(a.begin(),a.end(),cmp);
    sort(b.begin(),b.end(),cmp);
    sort(c.begin(),c.end(),cmp);

    memset(dp,-1,sizeof(dp));
    dp1(0,0,0,a,b,c);
    cout<<ans;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;

int ans=0;
long long dp[201][201][201];
int dp1(int x,int y,int z,vector <int> a,vector <int> b,vector<int> c){
    if ((x==-1&&y==-1)||(x==-1&&z==-1)||(z==-1&&y==-1)) return 0;
    int S=0;
    if (x!=-1&&y!=-1&&z!=-1) if (dp[x][y][z]!=-1) return dp[x][y][z];
    if (x>-1&&y>-1){
        S=max(S,a[x]*b[y]+dp1(x-1,y-1,z,a,b,c));
    }
    if (x>-1&&z>-1){
        S=max(S,a[x]*c[z]+dp1(x-1,y,z-1,a,b,c));
    }
    if (y>-1&&z>-1){
        S=max(S,b[y]*c[z]+dp1(x,y-1,z-1,a,b,c));
    }
    ans=max(ans,S);
    return dp[x][y][z]=S;
}

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    vector <int> a,b,c;
    for (int i=1;i<=x;i++){
        int so;
        cin>>so;
        a.push_back(so);
    }
    for (int i=1;i<=y;i++){
        int so;
        cin>>so;
        b.push_back(so);
    }
    for (int i=1;i<=z;i++){
        int so;
        cin>>so;
        c.push_back(so);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());

    memset(dp,-1,sizeof(dp));
    dp1(a.size()-1,b.size()-1,c.size()-1,a,b,c);
    cout<<ans;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;

int ans=0;
long long dp[201][201][201];
int dp1(int x,int y,int z,vector <int> a,vector <int> b,vector<int> c){
    int S=0;

    if (dp[x][y][z]!=-1) return dp[x][y][z];
    if (x>-1&&y>-1){
        S=max(S,a[x]*b[y]+dp1(x-1,y-1,z,a,b,c));
    }
    if (x>-1&&z>-1){
        S=max(S,a[x]*c[z]+dp1(x-1,y,z-1,a,b,c));
    }
    if (y>-1&&z>-1){
        S=max(S,b[y]*c[z]+dp1(x,y-1,z-1,a,b,c));
    }
    ans=max(ans,S);
    return dp[x][y][z]=S;
}

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    vector <int> a,b,c;
    for (int i=1;i<=x;i++){
        int so;
        cin>>so;
        a.push_back(so);
    }
    for (int i=1;i<=y;i++){
        int so;
        cin>>so;
        b.push_back(so);
    }
    for (int i=1;i<=z;i++){
        int so;
        cin>>so;
        c.push_back(so);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());

    memset(dp,-1,sizeof(dp));
    dp1(a.size()-1,b.size()-1,c.size()-1,a,b,c);
    cout<<ans;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;

int ans=0;
long long dp[201][201][201];

bool cmp(int a,int b){
    return (a>b);
}

int dp1(int x,int y,int z,vector <int> a,vector <int> b,vector<int> c){
    if ((x>=a.size()&&y>=b.size())||(x>=a.size()&&z>=c.size())||(y>=b.size()&&z>=c.size())) return 0;
    int S=0;
    if (dp[x][y][z]!=-1) return dp[x][y][z];
    if (x<a.size()&&y<b.size()){
        S=max(S,a[x]*b[y]+dp1(x+1,y+1,z,a,b,c));
    }
    if (x<a.size()&&z<c.size()){

        S=max(S,a[x]*c[z]+dp1(x+1,y,z+1,a,b,c));
    }
    if (z<c.size()&&y<b.size()){

        S=max(S,b[y]*c[z]+dp1(x,y+1,z+1,a,b,c));
    }
   ans=max(ans,S);
   return dp[x][y][z]=S;
}

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    vector <int> a,b,c;
    a.resize(x);
    b.resize(y);
    c.resize(z);
    for (int i=0;i<x;i++)cin>>a[i];
    for (int i=0;i<y;i++)cin>>b[i];
    for (int i=0;i<z;i++)cin>>c[i];

    sort(a.begin(),a.end(),cmp);
    sort(b.begin(),b.end(),cmp);
    sort(c.begin(),c.end(),cmp);

    memset(dp,-1,sizeof(dp));
    dp1(0,0,0,a,b,c);
    cout<<ans;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    vector <int> a,b,c;
    for (int i=1;i<=x;i++){
        int so;
        cin>>so;
        a.push_back(so);
    }
    for (int i=1;i<=y;i++){
        int so;
        cin>>so;
        b.push_back(so);
    }
    for (int i=1;i<=z;i++){
        int so;
        cin>>so;
        c.push_back(so);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    int ans=0;
    int i,j,k;
    i=a.size()-1;j=b.size()-1;k=c.size()-1;

    while ((i>=0&&j>=0)||(i>=0&&k>=0)||(j>=0&&k>=0)){
    int max1,max2;
    if (a[i]>b[j]&&a[i]>c[k]){
        max1=a[i];
        i--;
        if (b[j]>c[k]){
            max2=b[j];
            j--;
        }
        else{
            max2=c[k];
            k--;
        }
    }
    else{
        if (a[i]<b[j]&&b[j]>c[k]){
            max1=b[j];
            j--;
            if (a[i]>c[k]){
                max2=a[i];
                i--;
            }
            else{
                max2=c[k];
                k--;
            }
        }
        else{
            max1=c[k];
            k--;
            if (a[i]>b[j]){
                max2=a[i];
                i--;
            }
            else{
                max2=b[j];
                j--;
            }
        }
    }
    ans+=max1*max2;
    }
    cout<<ans;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;

int ans=0;
long long dp[201][201][201];

bool cmp(int a,int b){
    return (a>b);
}

int dp1(int x,int y,int z,vector <int> a,vector <int> b,vector<int> c){
    cout<<x<<' '<<y<<' '<<z<<endl;
    int S=0;
    //if (x!=-1&&y!=-1&&z!=-1) if (dp[x][y][z]!=-1) return dp[x][y][z];
    if (x<a.size()&&y<b.size()){

        S=max(S,a[x]*b[y]+dp1(x+1,y+1,z,a,b,c));
    }
    if (x<a.size()&&z<c.size()){

        S=max(S,a[x]*c[z]+dp1(x+1,y,z+1,a,b,c));
    }
    if (z<c.size()&&y<b.size()){

        S=max(S,b[y]*c[z]+dp1(x,y+1,z+1,a,b,c));
    }
   ans=max(ans,S);
    return S;
}

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    vector <int> a,b,c;
    for (int i=1;i<=x;i++){
        int so;
        cin>>so;
        a.push_back(so);
    }
    for (int i=1;i<=y;i++){
        int so;
        cin>>so;
        b.push_back(so);
    }
    for (int i=1;i<=z;i++){
        int so;
        cin>>so;
        c.push_back(so);
    }
    sort(a.begin(),a.end(),cmp);
    sort(b.begin(),b.end(),cmp);
    sort(c.begin(),c.end(),cmp);
    for (int i:a) cout<<i<<endl;
    memset(dp,-1,sizeof(dp));
    dp1(0,0,0,a,b,c);
    cout<<ans;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    vector <int> a,b,c;
    for (int i=1;i<=x;i++){
        int so;
        cin>>so;
        a.push_back(so);
    }
    for (int i=1;i<=y;i++){
        int so;
        cin>>so;
        b.push_back(so);
    }
    for (int i=1;i<=z;i++){
        int so;
        cin>>so;
        c.push_back(so);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    unsigned int ans=0;
    int i,j,k;
    i=a.size()-1;j=b.size()-1;k=c.size()-1;

    while ((i>=0&&j>=0)||(i>=0&&k>=0)||(j>=0&&k>=0)){
    int max1,max2;
    if (a[i]>b[j]&&a[i]>c[k]){
        max1=a[i];
        i--;
        if (b[j]>c[k]){
            max2=b[j];
            j--;
        }
        else{
            max2=c[k];
            k--;
        }
    }
    else{
        if (a[i]<b[j]&&b[j]>c[k]){
            max1=b[j];
            j--;
            if (a[i]>c[k]){
                max2=a[i];
                i--;
            }
            else{
                max2=c[k];
                k--;
            }
        }
        else{
            max1=c[k];
            k--;
            if (a[i]>b[j]){
                max2=a[i];
                i--;
            }
            else{
                max2=b[j];
                j--;
            }
        }
    }
    ans+=max1*max2;
    }
    cout<<ans;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <stdio.h>
#include <string.h>
using namespace std;

int ans=0;
long long dp[205][205][205];

bool cmp(int a,int b){
    return (a>b);
}

int dp1(int x,int y,int z,vector <int> a,vector <int> b,vector<int> c){
    if ((x>=a.size()&&y>=b.size())||(x>=a.size()&&z>=c.size())||(y>=b.size()&&z>=c.size())) return 0;
    int S=0;
    if (dp[x][y][z]!=-1) return dp[x][y][z];
    if (x<a.size()&&y<b.size()){
        S=max(S,a[x]*b[y]+dp1(x+1,y+1,z,a,b,c));
    }
    if (x<a.size()&&z<c.size()){

        S=max(S,a[x]*c[z]+dp1(x+1,y,z+1,a,b,c));
    }
    if (z<c.size()&&y<b.size()){

        S=max(S,b[y]*c[z]+dp1(x,y+1,z+1,a,b,c));
    }
   ans=max(ans,S);
   return dp[x][y][z]=S;
}

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    vector <int> a,b,c;
    a.resize(x);
    b.resize(y);
    c.resize(z);
    for (int i=0;i<x;i++)cin>>a[i];
    for (int i=0;i<y;i++)cin>>b[i];
    for (int i=0;i<z;i++)cin>>c[i];

    sort(a.begin(),a.end(),cmp);
    sort(b.begin(),b.end(),cmp);
    sort(c.begin(),c.end(),cmp);

    memset(dp,-1,sizeof(dp));
    dp1(0,0,0,a,b,c);
    cout<<ans;
}


/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;

int main()
{
    int x,y,z;
    cin>>x>>y>>z;
    vector <unsigned int> a,b,c;
    for (int i=1;i<=x;i++){
        int so;
        cin>>so;
        a.push_back(so);
    }
    for (int i=1;i<=y;i++){
        int so;
        cin>>so;
        b.push_back(so);
    }
    for (int i=1;i<=z;i++){
        int so;
        cin>>so;
        c.push_back(so);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    unsigned int ans=0;
    int i,j,k;
    i=a.size()-1;j=b.size()-1;k=c.size()-1;

    while (i>=0&&j>=0&&k>=0){
    unsigned max1,max2;
    if (a[i]>b[j]&&a[i]>c[k]){
        max1=a[i];
        i--;
        if (b[j]>c[k]){
            max2=b[j];
            j--;
        }
        else{
            max2=c[k];
            k--;
        }
    }
    else{
        if (a[i]<b[j]&&b[j]>c[k]){
            max1=b[j];
            j--;
            if (a[i]>c[k]){
                max2=a[i];
                i--;
            }
            else{
                max2=c[k];
                k--;
            }
        }
        else{
            max1=c[k];
            k--;
            if (a[i]>b[j]){
                max2=a[i];
                i--;
            }
            else{
                max2=b[j];
                j--;
            }
        }
    }

    ans+=max1*max2;
    }
    if (i==-1){
        while(j>-1&&k>-1){
            ans+=b[j]*c[k];
            j--;k--;
        }
    }
    else if (j==-1){
            while(i>-1&&k>-1){
                ans+=a[i]*c[k];
                i--;k--;
             }
    }
    else{
         while(i>-1&&j>-1){
                ans+=a[i]*b[j];
                i--;j--;
             }
    }
    cout<<ans;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define repo(i, n) for (int i = 1; i <= n; i++)
#define foreach(c, itr) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); itr++)
#define fastIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define eps 1e-6
#define pi 3.141592653589793
#define c(a) cout << a << "\n";
#define ao(a)        \
    for (auto i : a) \
        cout << i << " ";
#define endl '\n'
typedef vector<int> vii;
typedef vector<int> vll;
typedef pair<int, int> pii;
typedef pair<int, int> pll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 2e5 + 4;

int powmod(int a, int b, int mod)
{
    int res = 1;
    a %= mod;
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

int gcd(int a, int b)
{
    while (b > 0)
    {
        int t = a % b;
        a = b, b = t;
    }
    return a;
}

int lcm(int a, int b)
{
    return (a / gcd(a, b)) * b;
}

int is_prime(int n)
{
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}
int modI(int a, int m)
{
    int m0 = m, y = 0, x = 1;
    if (m == 1)
        return 0;
    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m;
        a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
        x += m0;
    return x;
}

long long mod_inv(long long a, long long m = MOD)
{
    return a == 1 ? 1 : m - mod_inv(m % a, a) * m / a;
}

long long choose(long long n, long long r)
{
    long long product = 1;

    for (long long i = 0; i < r; i++)
        product = product * (n - i) % MOD * mod_inv(i + 1) % MOD;

    return product;
}

int bit[N];

// void init(void){
//     int i;
//     rep(i,(1<<20)) v[i] = 0;
// }

void update(int idx, int val)
{
    while (idx <= N)
    {
        bit[idx] += val;
        idx += idx & -idx;
    }
}

// int pref(int idx)
// {
//     int ans = 0;
//     while (idx > 0)
//     {
//         ans += bit[idx];
//         idx -= idx & -idx;
//     }
//     return ans;
// }
// long long get(vector<long long> &f, int pos) {
//     long long res = 0;
//     for (; pos >= 0; pos = (pos & (pos + 1)) - 1)
//         res += f[pos];
//     return res;
// }

// void upd(vector<long long> &f, int pos, int val) {
//     for (; pos < int(f.size()); pos |= pos + 1) {
//         f[pos] += val;
//     }
// }
// int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
// int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
// int dx[4]={-1, +1, 0, 0};
// int dy[4]={0, 0, +1, -1};
/*************************************************************************************************************/
// bool prime[500000000];
// void pre()
// {
//     for (int i = 2; i < 500000000; i++)
//     {
//         if (!prime[i])
//         {
//             for (int j = 2 / i; j < 500000000; j += i)
//                 prime[j] = true;
//         }
//     }
// }
int r, b, g;
int rr[201], bb[201], gg[201];
ll cache1[201][201][201];
ll dp1(int i, int j, int k)
{
    if ((i > r && j > g) || (i > r && k > b) || (k > b && j > g))
        return 0;
    ll &ans = cache1[i][j][k];
    if (ans != -1)
        return ans;
    ans = 0;
    if (i <= r && j <= g)
        ans = rr[i] * gg[j] + dp1(i + 1, j + 1, k);
    if (i <= r && k <= b)
        ans = max(ans, rr[i] * bb[k] + dp1(i + 1, j, k + 1));
    if (k <= b && j <= g)
        ans = max(ans, gg[j] * bb[k] + dp1(i, j + 1, k + 1));

    return ans;
}

int main()
{
    cin >> r >> g >> b;
    for (int i = 1; i <= r; i++)
        cin >> rr[i];
    for (int i = 1; i <= g; i++)
        cin >> gg[i];
    for (int i = 1; i <= b; i++)
        cin >> bb[i];
    sort(rr + 1, rr + r + 1, greater<int>());
    sort(gg + 1, gg + g + 1, greater<int>());
    sort(bb + 1, bb + b + 1, greater<int>());
    rep(i, 201)
    {
        rep(j, 201)
        {
            rep(k, 201) cache1[i][j][k] = -1;
        }
    }
    ll ans1 = dp1(1, 1, 1);
    c(ans1) return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define repo(i, n) for (int i = 1; i <= n; i++)
#define foreach(c, itr) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); itr++)
#define fastIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define eps 1e-6
#define pi 3.141592653589793
#define c(a) cout << a << "\n";
#define ao(a)        \
    for (auto i : a) \
        cout << i << " ";
#define endl '\n'
typedef vector<int> vii;
typedef vector<int> vll;
typedef pair<int, int> pii;
typedef pair<int, int> pll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 2e5 + 4;

int powmod(int a, int b, int mod)
{
    int res = 1;
    a %= mod;
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

int gcd(int a, int b)
{
    while (b > 0)
    {
        int t = a % b;
        a = b, b = t;
    }
    return a;
}

int lcm(int a, int b)
{
    return (a / gcd(a, b)) * b;
}

int is_prime(int n)
{
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}
int modI(int a, int m)
{
    int m0 = m, y = 0, x = 1;
    if (m == 1)
        return 0;
    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m;
        a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
        x += m0;
    return x;
}

long long mod_inv(long long a, long long m = MOD)
{
    return a == 1 ? 1 : m - mod_inv(m % a, a) * m / a;
}

long long choose(long long n, long long r)
{
    long long product = 1;

    for (long long i = 0; i < r; i++)
        product = product * (n - i) % MOD * mod_inv(i + 1) % MOD;

    return product;
}

int bit[N];

// void init(void){
//     int i;
//     rep(i,(1<<20)) v[i] = 0;
// }

void update(int idx, int val)
{
    while (idx <= N)
    {
        bit[idx] += val;
        idx += idx & -idx;
    }
}

// int pref(int idx)
// {
//     int ans = 0;
//     while (idx > 0)
//     {
//         ans += bit[idx];
//         idx -= idx & -idx;
//     }
//     return ans;
// }
// long long get(vector<long long> &f, int pos) {
//     long long res = 0;
//     for (; pos >= 0; pos = (pos & (pos + 1)) - 1)
//         res += f[pos];
//     return res;
// }

// void upd(vector<long long> &f, int pos, int val) {
//     for (; pos < int(f.size()); pos |= pos + 1) {
//         f[pos] += val;
//     }
// }
// int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
// int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
// int dx[4]={-1, +1, 0, 0};
// int dy[4]={0, 0, +1, -1};
/*************************************************************************************************************/
// bool prime[500000000];
// void pre()
// {
//     for (int i = 2; i < 500000000; i++)
//     {
//         if (!prime[i])
//         {
//             for (int j = 2 / i; j < 500000000; j += i)
//                 prime[j] = true;
//         }
//     }
// }
int r, b, g;
int rr[201], bb[201], gg[201];
ll cache1[201][201][201];
ll dp1(int i, int j, int k)
{
    if ((i > r && j > g) || (i > r && k > b) || (k > b && j > g))
        return 0;
    ll &ans = cache1[i][j][k];
    if (ans != -1)
        return ans;
    ans = 0;
    //   if (i <= r && j <= g)
    ans = rr[i] * gg[j] + dp1(i + 1, j + 1, k);
    // if (i <= r && k <= b)
    ans = max(ans, rr[i] * bb[k] + dp1(i + 1, j, k + 1));
    // if (k <= b && j <= g)
    ans = max(ans, gg[j] * bb[k] + dp1(i, j + 1, k + 1));

    return ans;
}

int main()
{
    cin >> r >> g >> b;
    for (int i = 1; i <= r; i++)
        cin >> rr[i];
    for (int i = 1; i <= g; i++)
        cin >> gg[i];
    for (int i = 1; i <= b; i++)
        cin >> bb[i];
    sort(rr + 1, rr + r + 1, greater<int>());
    sort(gg + 1, gg + g + 1, greater<int>());
    sort(bb + 1, bb + b + 1, greater<int>());
    rep(i, 201)
    {
        rep(j, 201)
        {
            rep(k, 201) cache1[i][j][k] = -1;
        }
    }
    ll ans1 = dp1(1, 1, 1);
    c(ans1) return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define be begin()
#define en end()
#define le length()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define repo(i, n) for (int i = 1; i <= n; i++)
#define foreach(c, itr) for (__typeof((c).begin()) itr = (c).begin(); itr != (c).end(); itr++)
#define fastIO                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define eps 1e-6
#define pi 3.141592653589793
#define c(a) cout << a << "\n";
#define ao(a)        \
    for (auto i : a) \
        cout << i << " ";
#define endl '\n'
typedef vector<int> vii;
typedef vector<int> vll;
typedef pair<int, int> pii;
typedef pair<int, int> pll;
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 2e5 + 4;

int powmod(int a, int b, int mod)
{
    int res = 1;
    a %= mod;
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}

int gcd(int a, int b)
{
    while (b > 0)
    {
        int t = a % b;
        a = b, b = t;
    }
    return a;
}

int lcm(int a, int b)
{
    return (a / gcd(a, b)) * b;
}

int is_prime(int n)
{
    if (n <= 1 || n > 3 && (n % 2 == 0 || n % 3 == 0))
        return 0;
    for (int i = 5, t = 2; i * i <= n; i += t, t = 6 - t)
        if (n % i == 0)
            return 0;
    return 1;
}
int modI(int a, int m)
{
    int m0 = m, y = 0, x = 1;
    if (m == 1)
        return 0;
    while (a > 1)
    {
        int q = a / m;
        int t = m;
        m = a % m;
        a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
        x += m0;
    return x;
}

long long mod_inv(long long a, long long m = MOD)
{
    return a == 1 ? 1 : m - mod_inv(m % a, a) * m / a;
}

long long choose(long long n, long long r)
{
    long long product = 1;

    for (long long i = 0; i < r; i++)
        product = product * (n - i) % MOD * mod_inv(i + 1) % MOD;

    return product;
}

int bit[N];

// void init(void){
//     int i;
//     rep(i,(1<<20)) v[i] = 0;
// }

void update(int idx, int val)
{
    while (idx <= N)
    {
        bit[idx] += val;
        idx += idx & -idx;
    }
}

// int pref(int idx)
// {
//     int ans = 0;
//     while (idx > 0)
//     {
//         ans += bit[idx];
//         idx -= idx & -idx;
//     }
//     return ans;
// }
// long long get(vector<long long> &f, int pos) {
//     long long res = 0;
//     for (; pos >= 0; pos = (pos & (pos + 1)) - 1)
//         res += f[pos];
//     return res;
// }

// void upd(vector<long long> &f, int pos, int val) {
//     for (; pos < int(f.size()); pos |= pos + 1) {
//         f[pos] += val;
//     }
// }
// int dx[] = {-1, -1, -1, 0, 0, 0, 1, 1, 1};
// int dy[] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
// int dx[4]={-1, +1, 0, 0};
// int dy[4]={0, 0, +1, -1};
/*************************************************************************************************************/
// bool prime[500000000];
// void pre()
// {
//     for (int i = 2; i < 500000000; i++)
//     {
//         if (!prime[i])
//         {
//             for (int j = 2 / i; j < 500000000; j += i)
//                 prime[j] = true;
//         }
//     }
// }
int main()
{

    ll r, b, g;
    cin >> r >> b >> g;
    priority_queue<ll> p1, p2, p3;
    rep(i, r)
    {
        ll x;
        cin >> x;
        p1.push(x);
    }
    rep(i, b)
    {
        ll x;
        cin >> x;
        p2.push(x);
    }
    rep(i, g)
    {
        ll x;
        cin >> x;
        p3.push(x);
    }
    ll sum = 0;

    while (true)
    {
        int a[3] = {0};
        if (p1.size())
            a[0] = p1.size();
        if (p2.size())
            a[1] = p2.size();
        if (p3.size())
            a[2] = p3.size();
        // cout << a[0] << " " << a[1] << " " << a[2] << endl;
        sort(a, a + 3);
        if (a[0] == 0 && a[1] == 0)
            break;
        int b[3] = {0};
        if (p1.size())
            b[0] = p1.top();
        if (p2.size())
            b[1] = p2.top();
        if (p3.size())
            b[2] = p3.top();
        sort(b, b + 3);
        // ll ans = 0;
        if (p1.size() && b[2] == p1.top())
        {
            p1.pop();
            if (p2.size() && b[1] == p2.top())
                p2.pop();
            else
                p3.pop();
        }
        else if (p2.size() && b[2] == p2.top())
        {
            p2.pop();
            if (p1.size() && b[1] == p1.top())
                p1.pop();
            else
                p3.pop();
        }
        else if (p3.size() && b[2] == p3.top())
        {
            p3.pop();
            if (p2.size() && b[1] == p2.top())
                p2.pop();
            else
                p1.pop();
        }
        sum += b[1] * b[2];
        // c(sum)
    }
    c(sum)

        return 0;
}