#include<bits/stdc++.h>
using namespace std;

#define mod 998244353
//#define mod 1000000007

#define ll long long
const long long  maxn=31622778;

map<pair<ll,ll>,ll> mp;

const int MAXN=maxn;
int prime[MAXN+1];
void getPrime()
{
	memset(prime,0,sizeof(prime));
	for(int i=2;i<=MAXN;i++)
	{
		if(!prime[i])prime[++prime[0]]=i;
		for(int j=1;j<=prime[0]&&prime[j]<=MAXN/i;j++)
		{
			prime[prime[j]*i]=1;
			if(i%prime[j]==0) break;
		}
	}
}

/*
bool notprime[MAXN];//值为 false 表示素数，值为 true 表示非素数
void init(){
	memset(notprime,false,sizeof(notprime));
	notprime[0]=notprime[1]=true;
	for(int i=2;i<MAXN;i++)
	if(!notprime[i])
	{
	if(i>MAXN/i)continue;//防止后面 i*i 溢出 (或者 i,j 用 longlong)
	//直接从 i*i 开始就可以，小于 i 倍的已经筛选过了, 注意是 j+=i
	for(int j=i*i;j<MAXN;j+=i)
	notprime[j]=true;
	}
}

*/

ll jc(ll x,ll modk)
{
	ll ans=1;
	for(ll i=2;i<=x;i++)
		ans=ans*i%modk;
	return ans;
}

ll ksm(ll a,ll b,ll modk)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=(ans*a%modk+modk)%modk;
		a=a*a%modk+modk;a%=modk;
		b=b>>1;
	}
	return ans;
}

ll ny(ll a,ll modk)
{
	return ksm(a,modk-2,modk);
}

ll d;
ll u,v;
ll prime_d[200];

int main()
{

	getPrime();
	//init();
	//cout<<prime[0]<<endl;/////
	//cout<<(ll)prime[prime[0]]*(ll)prime[prime[0]]<<endl;///////////
	//cout<<prime[1000000]<<endl;
	cin>>d;
	ll dd=d;
	for(ll i=1;i<=prime[0]&&dd>1;i++)
	{
		if(dd%prime[i]==0)
		{
			prime_d[++prime_d[0]]=prime[i];
			while(dd%prime[i]==0)dd/=prime[i];
		}

	}
	if(dd>1)prime_d[++prime_d[0]]=dd;

	int t;
	cin>>t;
	//t=1;

	while(t--)
	{
		scanf("%lld%lld",&u,&v);
		if(u<v)swap(u,v);
		pair<ll,ll> save=make_pair(u,v);

		if(mp.count(save))
		{
			//cout<<"??"<<endl;
			cout<<mp[save]<<endl;
			continue;
		}
		ll w=__gcd(u,v);
		ll x=u/w,y=v/w;
		ll ansx=0,ansy=1;

		for(ll i=1;i<=prime_d[0]&&x>1;i++)
		{

			if(x%prime_d[i]==0)
			{
				ll cnt=0;
				//cout<<"!!"<<endl;///////////////////
				while(x%prime_d[i]==0)
				{
					cnt++;x/=prime_d[i];
				}
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
			}
			else
			{
				ll po=(ll)prime_d[i]*(ll)prime_d[i];
				if(x>maxn&&po>x||(i==prime_d[0]&&x>1))
				{
					//cout<<"??"<<endl;///////////////////
					ll cnt=1;
					ansx=(ansx+cnt)%mod;
					ansy=ansy*jc(cnt,mod)%mod;
					break;
				}
			}
		}
		ansx=jc(ansx,mod)*ny(ansy,mod)%mod;
		ll temp=ansx;
		//cout<<temp<<endl;///////////////////////////
		ansx=0;ansy=1;
		x=y;
		for(ll i=1;i<=prime_d[0]&&x>1;i++)
		{

			if(x%prime_d[i]==0)
			{
				ll cnt=0;
				while(x%prime_d[i]==0)
				{
					cnt++;x/=prime_d[i];
				}
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
			}
			else
			{
				ll po=(ll)prime_d[i]*(ll)prime_d[i];
				if(x>maxn&&po>x||(i==prime_d[0]&&x>1))
				{
					ll cnt=1;
					ansx=(ansx+cnt)%mod;
					ansy=ansy*jc(cnt,mod)%mod;
					break;
				}
			}
		}
		ansx=jc(ansx,mod)*ny(ansy,mod)%mod;
		ansx=ansx*temp%mod;
		mp[save]=ansx;
		printf("%lld\n",ansx);

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define mod 998244353
//#define mod 1000000007

#define ll long long
const long long  maxn=31622778;

map<pair<ll,ll>,ll> mp;

const int MAXN=maxn;
int prime[MAXN+1];
void getPrime()
{
	memset(prime,0,sizeof(prime));
	for(int i=2;i<=MAXN;i++)
	{
		if(!prime[i])prime[++prime[0]]=i;
		for(int j=1;j<=prime[0]&&prime[j]<=MAXN/i;j++)
		{
			prime[prime[j]*i]=1;
			if(i%prime[j]==0) break;
		}
	}
}

/*
bool notprime[MAXN];//值为 false 表示素数，值为 true 表示非素数
void init(){
	memset(notprime,false,sizeof(notprime));
	notprime[0]=notprime[1]=true;
	for(int i=2;i<MAXN;i++)
	if(!notprime[i])
	{
	if(i>MAXN/i)continue;//防止后面 i*i 溢出 (或者 i,j 用 longlong)
	//直接从 i*i 开始就可以，小于 i 倍的已经筛选过了, 注意是 j+=i
	for(int j=i*i;j<MAXN;j+=i)
	notprime[j]=true;
	}
}

*/

ll jc(ll x,ll modk)
{
	ll ans=1;
	for(ll i=2;i<=x;i++)
		ans=ans*i%modk;
	return ans;
}

ll ksm(ll a,ll b,ll modk)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=(ans*a%modk+modk)%modk;
		a=a*a%modk+modk;a%=modk;
		b=b>>1;
	}
	return ans;
}

ll ny(ll a,ll modk)
{
	return ksm(a,modk-2,modk);
}

ll d;
ll u,v;
ll prime_d[200];

int main()
{

	getPrime();
	//init();
	//cout<<prime[0]<<endl;/////
	//cout<<(ll)prime[prime[0]]*(ll)prime[prime[0]]<<endl;///////////
	//cout<<prime[1000000]<<endl;
	cin>>d;
	ll dd=d;
	for(ll i=1;i<=prime[0]&&dd>1;i++)
	{
		if(dd%prime[i]==0)
		{
			prime_d[++prime_d[0]]=prime[i];
			while(dd%prime[i]==0)dd/=prime[i];
		}

	}
	if(dd>1)prime_d[++prime_d[0]]=dd;

	int t;
	cin>>t;
	//t=1;

	while(t--)
	{
		scanf("%lld%lld",&u,&v);
		/*
		if(u<v)swap(u,v);
		pair<ll,ll> save=make_pair(u,v);

		if(mp.count(save))
		{
			//cout<<"??"<<endl;
			cout<<mp[save]<<endl;
			continue;
		}
		*/
		ll w=__gcd(u,v);
		ll x=u/w,y=v/w;
		ll ansx=0,ansy=1;

		for(ll i=1;i<=prime_d[0]&&x>1;i++)
		{

			if(x%prime_d[i]==0)
			{
				ll cnt=0;
				//cout<<"!!"<<endl;///////////////////
				while(x%prime_d[i]==0)
				{
					cnt++;x/=prime_d[i];
				}
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
			}
			else
			{
				ll po=(ll)prime_d[i]*(ll)prime_d[i];
				if(x>maxn&&po>x||(i==prime_d[0]&&x>1))
				{
					//cout<<"??"<<endl;///////////////////
					ll cnt=1;
					ansx=(ansx+cnt)%mod;
					ansy=ansy*jc(cnt,mod)%mod;
					break;
				}
			}
		}
		ansx=jc(ansx,mod)*ny(ansy,mod)%mod;
		ll temp=ansx;
		//cout<<temp<<endl;///////////////////////////
		ansx=0;ansy=1;
		x=y;
		for(ll i=1;i<=prime_d[0]&&x>1;i++)
		{

			if(x%prime_d[i]==0)
			{
				ll cnt=0;
				while(x%prime_d[i]==0)
				{
					cnt++;x/=prime_d[i];
				}
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
			}
			else
			{
				ll po=(ll)prime_d[i]*(ll)prime_d[i];
				if(x>maxn&&po>x||(i==prime_d[0]&&x>1))
				{
					ll cnt=1;
					ansx=(ansx+cnt)%mod;
					ansy=ansy*jc(cnt,mod)%mod;
					break;
				}
			}
		}
		ansx=jc(ansx,mod)*ny(ansy,mod)%mod;
		ansx=ansx*temp%mod;
		//mp[save]=ansx;
		printf("%lld\n",ansx);

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define mod 998244353
//#define mod 1000000007

#define ll long long
const long long  maxn=31622778;

const int MAXN=maxn;
int prime[MAXN+1];
void getPrime()
{
	memset(prime,0,sizeof(prime));
	for(int i=2;i<=MAXN;i++)
	{
		if(!prime[i])prime[++prime[0]]=i;
		for(int j=1;j<=prime[0]&&prime[j]<=MAXN/i;j++)
		{
			prime[prime[j]*i]=1;
			if(i%prime[j]==0) break;
		}
	}
}

bool notprime[MAXN];//值为 false 表示素数，值为 true 表示非素数
void init(){
	memset(notprime,false,sizeof(notprime));
	notprime[0]=notprime[1]=true;
	for(int i=2;i<MAXN;i++)
	if(!notprime[i])
	{
	if(i>MAXN/i)continue;//防止后面 i*i 溢出 (或者 i,j 用 longlong)
	//直接从 i*i 开始就可以，小于 i 倍的已经筛选过了, 注意是 j+=i
	for(int j=i*i;j<MAXN;j+=i)
	notprime[j]=true;
	}
}

ll jc(ll x,ll modk)
{
	ll ans=1;
	for(ll i=2;i<=x;i++)
		ans=ans*i%modk;
	return ans;
}

ll ksm(ll a,ll b,ll modk)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=(ans*a%modk+modk)%modk;
		a=a*a%modk+modk;a%=modk;
		b=b>>1;
	}
	return ans;
}

ll ny(ll a,ll modk)
{
	return ksm(a,modk-2,modk);
}

ll d;
ll u,v;

int main()
{

	getPrime();
	init();
	//cout<<prime[0]<<endl;/////
	//cout<<(ll)prime[prime[0]]*(ll)prime[prime[0]]<<endl;///////////

	cin>>d;

	int t;
	cin>>t;
	//t=1;

	while(t--)
	{
		scanf("%lld%lld",&u,&v);
		ll w=__gcd(u,v);
		ll x=u/w,y=v/w;
		ll ansx=0,ansy=1;

		for(ll i=1;i<=prime[0]&&x>1;i++)
		{
			if(x<maxn&&(!notprime[x]))
			{

				ll cnt=1;
				//cout<<"??"<<endl;///////////////////
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
				x=1;
				break;
			}
			else if(x%prime[i]==0)
			{
				ll cnt=0;
				//cout<<"!!"<<endl;///////////////////
				while(x%prime[i]==0)
				{
					cnt++;x/=prime[i];
				}
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
			}
			else
			{
				ll po=(ll)prime[i]*(ll)prime[i];
				if(po>x||(i==prime[0]&&x>1))
				{
					//cout<<"??"<<endl;///////////////////
					ll cnt=1;
					ansx=(ansx+cnt)%mod;
					ansy=ansy*jc(cnt,mod)%mod;
					break;
				}
			}
		}
		ansx=jc(ansx,mod)*ny(ansy,mod)%mod;
		ll temp=ansx;
		//cout<<temp<<endl;///////////////////////////
		ansx=0;ansy=1;
		x=y;
		for(ll i=1;i<=prime[0]&&x>1;i++)
		{
			if(x<maxn&&(!notprime[x]))
			{
				ll cnt=1;
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
				x=1;
				break;
			}
			else if(x%prime[i]==0)
			{
				ll cnt=0;
				while(x%prime[i]==0)
				{
					cnt++;x/=prime[i];
				}
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
			}
			else
			{
				ll po=(ll)prime[i]*(ll)prime[i];
				if(po>x||(i==prime[0]&&x>1))
				{
					ll cnt=1;
					ansx=(ansx+cnt)%mod;
					ansy=ansy*jc(cnt,mod)%mod;
					break;
				}
			}
		}
		ansx=jc(ansx,mod)*ny(ansy,mod)%mod;
		ansx=ansx*temp%mod;
		printf("%lld\n",ansx);

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define mod 998244353
//#define mod 1000000007

#define ll long long
const long long  maxn=3e7+2e6;

const int MAXN=maxn;
int prime[MAXN+1];
void getPrime()
{
	memset(prime,0,sizeof(prime));
	for(int i=2;i<=MAXN;i++)
	{
		if(!prime[i])prime[++prime[0]]=i;
		for(int j=1;j<=prime[0]&&prime[j]<=MAXN/i;j++)
		{
			prime[prime[j]*i]=1;
			if(i%prime[j]==0) break;
		}
	}
}

/*
bool notprime[MAXN];//值为 false 表示素数，值为 true 表示非素数
void init(){
	memset(notprime,false,sizeof(notprime));
	notprime[0]=notprime[1]=true;
	for(int i=2;i<MAXN;i++)
	if(!notprime[i])
	{
	if(i>MAXN/i)continue;//防止后面 i*i 溢出 (或者 i,j 用 longlong)
	//直接从 i*i 开始就可以，小于 i 倍的已经筛选过了, 注意是 j+=i
	for(int j=i*i;j<MAXN;j+=i)
	notprime[j]=true;
	}
}
*/
ll jc(ll x,ll modk)
{
	ll ans=1;
	for(ll i=2;i<=x;i++)
		ans=ans*i%modk;
	return ans;
}

ll ksm(ll a,ll b,ll modk)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=(ans*a%modk+modk)%modk;
		a=a*a%modk+modk;a%=modk;
		b=b>>1;
	}
	return ans;
}

ll ny(ll a,ll modk)
{
	return ksm(a,modk-2,modk);
}

ll d;
ll u,v;

int main()
{

	getPrime();
	//cout<<prime[0]<<endl;/////
	cin>>d;

	int t;
	cin>>t;
	//t=1;

	while(t--)
	{
		scanf("%lld%lld",&u,&v);
		ll w=__gcd(u,v);
		ll x=u/w,y=v/w;
		ll ansx=0,ansy=1;
		for(ll i=1;i<=prime[0]&&x>1;i++)
		{
			if(x%prime[i]==0)
			{
				ll cnt=0;
				while(x%prime[i]==0)
				{
					cnt++;x/=prime[i];
				}
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
			}
			else if(i==prime[0]&&x>1)
			{
				ll cnt=1;
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
			}
		}
		ansx=jc(ansx,mod)*ny(ansy,mod)%mod;
		ll temp=ansx;
		//cout<<temp<<endl;///////////////////////////
		ansx=0;ansy=1;
		x=y;
		for(ll i=1;i<=prime[0]&&x>1;i++)
		{
			if(x%prime[i]==0)
			{
				ll cnt=0;
				while(x%prime[i]==0)
				{
					cnt++;x/=prime[i];
				}
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
			}
			else if(i==prime[0]&&x>1)
			{
				ll cnt=1;
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
			}
		}
		ansx=jc(ansx,mod)*ny(ansy,mod)%mod;
		ansx=ansx*temp%mod;
		printf("%lld\n",ansx);

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define mod 998244353
//#define mod 1000000007

#define ll long long
const long long  maxn=31622778;

map<pair<ll,ll>,ll> mp;

const int MAXN=maxn;
int prime[MAXN+1];
void getPrime()
{
	memset(prime,0,sizeof(prime));
	for(int i=2;i<=MAXN;i++)
	{
		if(!prime[i])prime[++prime[0]]=i;
		for(int j=1;j<=prime[0]&&prime[j]<=MAXN/i;j++)
		{
			prime[prime[j]*i]=1;
			if(i%prime[j]==0) break;
		}
	}
}

bool notprime[MAXN];//值为 false 表示素数，值为 true 表示非素数
void init(){
	memset(notprime,false,sizeof(notprime));
	notprime[0]=notprime[1]=true;
	for(int i=2;i<MAXN;i++)
	if(!notprime[i])
	{
	if(i>MAXN/i)continue;//防止后面 i*i 溢出 (或者 i,j 用 longlong)
	//直接从 i*i 开始就可以，小于 i 倍的已经筛选过了, 注意是 j+=i
	for(int j=i*i;j<MAXN;j+=i)
	notprime[j]=true;
	}
}

ll jc(ll x,ll modk)
{
	ll ans=1;
	for(ll i=2;i<=x;i++)
		ans=ans*i%modk;
	return ans;
}

ll ksm(ll a,ll b,ll modk)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=(ans*a%modk+modk)%modk;
		a=a*a%modk+modk;a%=modk;
		b=b>>1;
	}
	return ans;
}

ll ny(ll a,ll modk)
{
	return ksm(a,modk-2,modk);
}

ll d;
ll u,v;

int main()
{

	getPrime();
	init();
	//cout<<prime[0]<<endl;/////
	//cout<<(ll)prime[prime[0]]*(ll)prime[prime[0]]<<endl;///////////
	//cout<<prime[1000000]<<endl;
	cin>>d;

	int t;
	cin>>t;
	//t=1;

	while(t--)
	{
		scanf("%lld%lld",&u,&v);
		if(u<v)swap(u,v);
		pair<ll,ll> save=make_pair(u,v);

		if(mp.count(save))
		{
			//cout<<"??"<<endl;
			cout<<mp[save]<<endl;
			continue;
		}
		ll w=__gcd(u,v);
		ll x=u/w,y=v/w;
		ll ansx=0,ansy=1;

		for(ll i=1;i<=prime[0]&&x>1;i++)
		{
			if(x<maxn&&(!notprime[x]))
			{

				ll cnt=1;
				//cout<<"??"<<endl;///////////////////
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
				x=1;
				break;
			}
			else if(x%prime[i]==0)
			{
				ll cnt=0;
				//cout<<"!!"<<endl;///////////////////
				while(x%prime[i]==0)
				{
					cnt++;x/=prime[i];
				}
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
			}
			else
			{
				ll po=(ll)prime[i]*(ll)prime[i];
				if(po>x||(i==prime[0]&&x>1))
				{
					//cout<<"??"<<endl;///////////////////
					ll cnt=1;
					ansx=(ansx+cnt)%mod;
					ansy=ansy*jc(cnt,mod)%mod;
					break;
				}
			}
		}
		ansx=jc(ansx,mod)*ny(ansy,mod)%mod;
		ll temp=ansx;
		//cout<<temp<<endl;///////////////////////////
		ansx=0;ansy=1;
		x=y;
		for(ll i=1;i<=prime[0]&&x>1;i++)
		{
			if(x<maxn&&(!notprime[x]))
			{
				ll cnt=1;
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
				x=1;
				break;
			}
			else if(x%prime[i]==0)
			{
				ll cnt=0;
				while(x%prime[i]==0)
				{
					cnt++;x/=prime[i];
				}
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
			}
			else
			{
				ll po=(ll)prime[i]*(ll)prime[i];
				if(po>x||(i==prime[0]&&x>1))
				{
					ll cnt=1;
					ansx=(ansx+cnt)%mod;
					ansy=ansy*jc(cnt,mod)%mod;
					break;
				}
			}
		}
		ansx=jc(ansx,mod)*ny(ansy,mod)%mod;
		ansx=ansx*temp%mod;
		mp[save]=ansx;
		printf("%lld\n",ansx);

	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define mod 998244353
//#define mod 1000000007

#define ll long long
const long long  maxn=31622778;

map<pair<ll,ll>,ll> mp;

const int MAXN=maxn;
int prime[MAXN+1];
void getPrime()
{
	memset(prime,0,sizeof(prime));
	for(int i=2;i<=MAXN;i++)
	{
		if(!prime[i])prime[++prime[0]]=i;
		for(int j=1;j<=prime[0]&&prime[j]<=MAXN/i;j++)
		{
			prime[prime[j]*i]=1;
			if(i%prime[j]==0) break;
		}
	}
}

bool notprime[MAXN];//值为 false 表示素数，值为 true 表示非素数
void init(){
	memset(notprime,false,sizeof(notprime));
	notprime[0]=notprime[1]=true;
	for(int i=2;i<MAXN;i++)
	if(!notprime[i])
	{
	if(i>MAXN/i)continue;//防止后面 i*i 溢出 (或者 i,j 用 longlong)
	//直接从 i*i 开始就可以，小于 i 倍的已经筛选过了, 注意是 j+=i
	for(int j=i*i;j<MAXN;j+=i)
	notprime[j]=true;
	}
}

ll jc(ll x,ll modk)
{
	ll ans=1;
	for(ll i=2;i<=x;i++)
		ans=ans*i%modk;
	return ans;
}

ll ksm(ll a,ll b,ll modk)
{
	ll ans=1;
	while(b)
	{
		if(b&1)ans=(ans*a%modk+modk)%modk;
		a=a*a%modk+modk;a%=modk;
		b=b>>1;
	}
	return ans;
}

ll ny(ll a,ll modk)
{
	return ksm(a,modk-2,modk);
}

ll d;
ll u,v;
ll prime_d[200];

int main()
{

	getPrime();
	init();
	//cout<<prime[0]<<endl;/////
	//cout<<(ll)prime[prime[0]]*(ll)prime[prime[0]]<<endl;///////////
	//cout<<prime[1000000]<<endl;
	cin>>d;
	ll dd=d;
	for(ll i=1;i<=prime[0]&&dd>1;i++)
	{
		if(dd%prime[i]==0)
		{
			prime_d[++prime_d[0]]=prime[i];
			while(dd%prime[i]==0)dd/=prime[i];
		}

	}
	if(dd>1)prime_d[++prime_d[0]]=dd;

	int t;
	cin>>t;
	//t=1;

	while(t--)
	{
		scanf("%lld%lld",&u,&v);
		if(u<v)swap(u,v);
		pair<ll,ll> save=make_pair(u,v);

		if(mp.count(save))
		{
			//cout<<"??"<<endl;
			cout<<mp[save]<<endl;
			continue;
		}
		ll w=__gcd(u,v);
		ll x=u/w,y=v/w;
		ll ansx=0,ansy=1;

		for(ll i=1;i<=prime_d[0]&&x>1;i++)
		{
			if(x<maxn&&(!notprime[x]))
			{

				ll cnt=1;
				//cout<<"??"<<endl;///////////////////
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
				x=1;
				break;
			}
			else if(x%prime_d[i]==0)
			{
				ll cnt=0;
				//cout<<"!!"<<endl;///////////////////
				while(x%prime_d[i]==0)
				{
					cnt++;x/=prime_d[i];
				}
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
			}
			else
			{
				ll po=(ll)prime_d[i]*(ll)prime_d[i];
				if(po>x||(i==prime_d[0]&&x>1))
				{
					//cout<<"??"<<endl;///////////////////
					ll cnt=1;
					ansx=(ansx+cnt)%mod;
					ansy=ansy*jc(cnt,mod)%mod;
					break;
				}
			}
		}
		ansx=jc(ansx,mod)*ny(ansy,mod)%mod;
		ll temp=ansx;
		//cout<<temp<<endl;///////////////////////////
		ansx=0;ansy=1;
		x=y;
		for(ll i=1;i<=prime_d[0]&&x>1;i++)
		{
			if(x<maxn&&(!notprime[x]))
			{
				ll cnt=1;
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
				x=1;
				break;
			}
			else if(x%prime_d[i]==0)
			{
				ll cnt=0;
				while(x%prime_d[i]==0)
				{
					cnt++;x/=prime_d[i];
				}
				ansx=(ansx+cnt)%mod;
				ansy=ansy*jc(cnt,mod)%mod;
			}
			else
			{
				ll po=(ll)prime_d[i]*(ll)prime_d[i];
				if(po>x||(i==prime_d[0]&&x>1))
				{
					ll cnt=1;
					ansx=(ansx+cnt)%mod;
					ansy=ansy*jc(cnt,mod)%mod;
					break;
				}
			}
		}
		ansx=jc(ansx,mod)*ny(ansy,mod)%mod;
		ansx=ansx*temp%mod;
		mp[save]=ansx;
		printf("%lld\n",ansx);

	}

	return 0;
}


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sqr(x) (x) * (x)

using namespace std;

//mt19937_64 gen(time(0));
const ll mod = 998244353;
//const int inf = 1e9 + 45522;

ll binpow (ll a, ll n)
{
	if (n == 0)
		return 1;
	if (n % 2 == 1)
    {
		return (binpow(a, n - 1) * a) % mod;;
    }
	else
    {
		ll b = binpow(a, n / 2);
		return (b * b) % mod;
	}
}

ll f[500];
ll f_obr[500];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
#endif
    f[0] = 1;
    f_obr[0] = 1;
    for(ll i = 1; i < 500; ++i)
    {
        f[i] = f[i - 1] * i;
        f[i] %= mod;
        f_obr[i] = binpow(f[i], mod - 2);
    }

    ll d;
    cin >> d;
    vector <ll> pr;
    pr.reserve(1e7 + 5);
    for(ll i = 2; i * i <= d; ++i)
    {
        if (d % i == 0)
        {
            pr.pb(i);
            while(d % i == 0) d /= i;
        }
    }
    if (d > 1) pr.pb(d);
    int q;
    cin >> q;
    for(int i = 0; i < q; ++i)
    {
        ll v[2];
        cin >> v[0] >> v[1];
        vector <ll> vc[2];
        vector <int> cnt[2];
        for(int j = 0; j < 2; ++j)
            for(int k = 0; k < int(pr.size()); ++k)
                if (v[j] % pr[k] == 0)
                {
                    vc[j].pb(pr[k]);
                    cnt[j].pb(0);
                    while(v[j] % pr[k] == 0)
                    {
                        cnt[j].back()++;
                        v[j] /= pr[k];
                    }
//                    cerr << pr[k] << '\n';
                }
        int uk = 0;
        vector <int> res[2];
        for(int j = 0; j < int(cnt[0].size()); ++j)
        {
            while(uk < int(cnt[1].size()) && vc[1][uk] <= vc[0][j])
            {
                if (vc[1][uk] == vc[0][j])
                {
                    if(cnt[0][j] > cnt[1][uk])
                        res[0].pb(cnt[0][j] - cnt[1][uk]);
                    else
                        res[1].pb(cnt[1][uk] - cnt[0][j]);
                }
                else
                    res[1].pb(cnt[1][uk]);
                ++uk;
            }
            if (!(uk > 0 && vc[1][uk - 1] == vc[0][j]))
                res[0].pb(cnt[0][j]);
        }
        while(uk < int(cnt[1].size()))
        {
            res[1].pb(cnt[1][uk]);
            ++uk;
        }
        int sum[2];
        sum[0] = 0;
        sum[1] = 0;
        ll ans = 1;
        for(int j = 0; j < 2; ++j)
            for(int k = 0; k < int(res[j].size()); ++k)
            {
                sum[j] += res[j][k];
                ans *= f_obr[res[j][k]];
                ans %= mod;
            }
//        cerr << sum[0] << ' ' << sum[1] << endl;
        ans *= f[sum[0]];
        ans %= mod;
        ans *= f[sum[1]];
        ans %= mod;
        cout << ans << '\n';
    }
	return 0;
}

//288807105787200
//1
//46 482955026400


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sqr(x) (x) * (x)

using namespace std;

//mt19937_64 gen(time(0));
const ll mod = 998244353;
//const int inf = 1e9 + 45522;

ll binpow (ll a, ll n)
{
	if (n == 0)
		return 1;
	if (n % 2 == 1)
    {
		return (binpow(a, n - 1) * a) % mod;;
    }
	else
    {
		ll b = binpow(a, n / 2);
		return (b * b) % mod;
	}
}

ll f[500];
ll f_obr[500];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
#endif
    f[0] = 1;
    f_obr[0] = 1;
    for(ll i = 1; i < 500; ++i)
    {
        f[i] = f[i - 1] * i;
        f[i] %= mod;
        f_obr[i] = binpow(f[i], mod - 2);
    }

    ll d;
    cin >> d;
    vector <ll> pr;
    pr.reserve(1e7 + 5);
    for(ll i = 2; i * i <= d; ++i)
    {
        if (d % i == 0)
        {
            pr.pb(i);
            while(d % i == 0) d /= i;
        }
    }
    if (d > 1) pr.pb(d);
    int q;
    cin >> q;
    for(int i = 0; i < q; ++i)
    {
        ll v[2];
        cin >> v[0] >> v[1];
        vector <ll> vc[2];
        vector <int> cnt[2];
        for(int j = 0; j < 2; ++j)
            for(int k = 0; k < int(pr.size()); ++k)
                if (v[j] % pr[k] == 0)
                {
                    vc[j].pb(pr[k]);
                    cnt[j].pb(0);
                    while(v[j] % pr[k] == 0)
                    {
                        cnt[j].back()++;
                        v[j] /= pr[k];
                    }
//                    cerr << pr[k] << '\n';
                }
        int uk = 0;
        vector <int> res[2];
        for(int j = 0; j < int(cnt[0].size()); ++j)
        {
            while(uk < int(cnt[1].size()) && vc[1][uk] <= vc[0][j])
            {
                if (vc[1][uk] == vc[0][j])
                {
                    if(cnt[0][j] > cnt[1][uk])
                        res[0].pb(cnt[0][j] - cnt[1][uk]);
                    else
                        res[1].pb(cnt[1][uk] - cnt[0][j]);
                }
                else
                    res[1].pb(cnt[1][uk]);
                ++uk;
            }
            if (!(uk > 0 && vc[1][uk - 1] == vc[0][j]))
                res[0].pb(cnt[0][j]);
        }
        while(uk < int(cnt[1].size()))
        {
            res[1].pb(cnt[1][uk]);
            ++uk;
        }
        int sum[2];
        sum[0] = 0;
        sum[1] = 0;
        ll ans = 1;
        for(int j = 0; j < 2; ++j)
            for(int k = 0; k < int(res[j].size()); ++k)
            {
                sum[j] += res[j][k];
                ans *= f_obr[res[j][k]];
                ans %= mod;
            }
        cerr << sum[0] << ' ' << sum[1] << endl;
        ans *= f[sum[0]];
        ans %= mod;
        ans *= f[sum[1]];
        ans %= mod;
        cout << ans << '\n';
    }
	return 0;
}

//288807105787200
//1
//46 482955026400


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sqr(x) (x) * (x)

using namespace std;

//mt19937_64 gen(time(0));
const ll mod = 998244353;
//const int inf = 1e9 + 45522;

ll binpow (ll a, ll n)
{
	if (n == 0)
		return 1;
	if (n % 2 == 1)
    {
		return (binpow(a, n - 1) * a) % mod;;
    }
	else
    {
		ll b = binpow(a, n / 2);
		return (b * b) % mod;
	}
}

ll f[500];
ll f_obr[500];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#else
#endif
    f[0] = 1;
    f_obr[0] = 1;
    for(ll i = 1; i < 500; ++i)
    {
        f[i] = f[i - 1] * i;
        f[i] %= mod;
        f_obr[i] = binpow(f[i], mod - 2);
    }

    ll d;
    cin >> d;
    vector <ll> pr;
    pr.reserve(1e7 + 5);
    for(ll i = 2; i * i <= d; ++i)
    {
        if (d % i == 0)
        {
            pr.pb(i);
            while(d % i == 0) d /= i;
        }
    }
    if (d > 1) pr.pb(d);
    int q;
    cin >> q;
    for(int i = 0; i < q; ++i)
    {
        ll v[2];
        cin >> v[0] >> v[1];
        vector <int> vc[2];
        vector <int> cnt[2];
        for(int j = 0; j < 2; ++j)
            for(int k = 0; k < int(pr.size()); ++k)
                if (v[j] % pr[k] == 0)
                {
                    vc[j].pb(pr[k]);
                    cnt[j].pb(0);
                    while(v[j] % pr[k] == 0)
                    {
                        cnt[j].back()++;
                        v[j] /= pr[k];
                    }
                }
        int uk = 0;
        vector <int> res[2];
        for(int j = 0; j < int(cnt[0].size()); ++j)
        {
            while(uk < int(cnt[1].size()) && vc[1][uk] <= vc[0][j])
            {
                if (vc[1][uk] == vc[0][j])
                {
                    if(cnt[0][j] > cnt[1][j])
                        res[0].pb(cnt[0][j] - cnt[1][uk]);
                    else
                        res[1].pb(cnt[1][uk] - cnt[0][j]);
                }
                else
                    res[1].pb(cnt[1][uk]);
                ++uk;
            }
            if (!(uk > 0 && vc[1][uk - 1] == vc[0][j]))
                res[0].pb(cnt[0][j]);
        }
        while(uk < int(cnt[1].size()))
        {
            res[1].pb(cnt[1][uk]);
            ++uk;
        }
        int sum[2];
        sum[0] = 0;
        sum[1] = 0;
        ll ans = 1;
        for(int j = 0; j < 2; ++j)
            for(int k = 0; k < int(res[j].size()); ++k)
            {
                sum[j] += res[j][k];
                ans *= f_obr[res[j][k]];
                ans %= mod;
            }
        ans *= f[sum[0]];
        ans %= mod;
        ans *= f[sum[1]];
        ans %= mod;
        cout << ans << '\n';
    }
	return 0;
}

//288807105787200
//1
//46 482955026400


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sqr(x) (x) * (x)

using namespace std;

//mt19937_64 gen(time(0));
const ll mod = 998244353;
//const int inf = 1e9 + 45522;

ll binpow (ll a, ll n)
{
	if (n == 0)
		return 1;
	if (n % 2 == 1)
    {
		return (binpow(a, n - 1) * a) % mod;;
    }
	else
    {
		ll b = binpow(a, n / 2);
		return (b * b) % mod;
	}
}

ll f[500];
ll f_obr[500];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#else
#endif
    f[0] = 1;
    f_obr[0] = 1;
    for(ll i = 1; i < 500; ++i)
    {
        f[i] = f[i - 1] * i;
        f[i] %= mod;
        f_obr[i] = binpow(f[i], mod - 2);
    }

    ll d;
    cin >> d;
    vector <ll> pr;
    pr.reserve(1e7 + 5);
    for(ll i = 2; i * i <= d; ++i)
    {
        if (d % i == 0)
        {
            pr.pb(i);
            while(d % i == 0) d /= i;
        }
    }
    if (d > 1) pr.pb(d);
    int q;
    cin >> q;
    for(int i = 0; i < q; ++i)
    {
        ll v[2];
        cin >> v[0] >> v[1];
        vector <int> vc[2];
        vector <int> cnt[2];
        for(int j = 0; j < 2; ++j)
            for(int k = 0; k < int(pr.size()); ++k)
                if (v[j] % pr[k] == 0)
                {
                    vc[j].pb(pr[k]);
                    cnt[j].pb(0);
                    while(v[j] % pr[k] == 0)
                    {
                        cnt[j].back()++;
                        v[j] /= pr[k];
                    }
                }
        int uk = 0;
        vector <int> res[2];
        for(int j = 0; j < int(cnt[0].size()); ++j)
        {
            while(uk < int(cnt[1].size()) && vc[1][uk] <= vc[0][j])
            {
                if (vc[1][uk] == vc[0][j])
                {
                    if(cnt[0][j] > cnt[1][uk])
                        res[0].pb(cnt[0][j] - cnt[1][uk]);
                    else
                        res[1].pb(cnt[1][uk] - cnt[0][j]);
                }
                else
                    res[1].pb(cnt[1][uk]);
                ++uk;
            }
            if (!(uk > 0 && vc[1][uk - 1] == vc[0][j]))
                res[0].pb(cnt[0][j]);
        }
        while(uk < int(cnt[1].size()))
        {
            res[1].pb(cnt[1][uk]);
            ++uk;
        }
        int sum[2];
        sum[0] = 0;
        sum[1] = 0;
        ll ans = 1;
        for(int j = 0; j < 2; ++j)
            for(int k = 0; k < int(res[j].size()); ++k)
            {
                sum[j] += res[j][k];
                ans *= f_obr[res[j][k]];
                ans %= mod;
            }
        ans *= f[sum[0]];
        ans %= mod;
        ans *= f[sum[1]];
        ans %= mod;
        cout << ans << '\n';
    }
	return 0;
}

//288807105787200
//1
//46 482955026400


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sqr(x) (x) * (x)

using namespace std;

//mt19937_64 gen(time(0));
const ll mod = 998244353;
//const int inf = 1e9 + 45522;

ll binpow (ll a, ll n)
{
	if (n == 0)
		return 1;
	if (n % 2 == 1)
    {
		return (binpow(a, n - 1) * a) % mod;;
    }
	else
    {
		ll b = binpow(a, n / 2);
		return (b * b) % mod;
	}
}

ll f[500];
ll f_obr[500];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
#endif
    f[0] = 1;
    f_obr[0] = 1;
    for(ll i = 1; i < 500; ++i)
    {
        f[i] = f[i - 1] * i;
        f[i] %= mod;
        f_obr[i] = binpow(f[i], mod - 2);
    }

    ll d;
    cin >> d;
    vector <ll> pr;
    pr.reserve(500);
    for(ll i = 2; i * i <= d; ++i)
    {
        if (d % i == 0)
        {
            pr.pb(i);
            while(d % i == 0) d /= i;
        }
    }
    if (d > 1) pr.pb(d);
    int q;
    cin >> q;
    vector <ll> vc[2];
    vector <int> cnt[2];
    vector <int> res[2];
    vc[0].reserve(500);
    vc[1].reserve(500);
    cnt[0].reserve(500);
    cnt[1].reserve(500);
    res[0].reserve(500);
    res[1].reserve(500);
    for(int i = 0; i < q; ++i)
    {
        ll v[2];
        cin >> v[0] >> v[1];
        vc[0].clear();
        vc[1].clear();
        cnt[0].clear();
        cnt[1].clear();
        res[0].clear();
        res[1].clear();
        for(int j = 0; j < 2; ++j)
            for(int k = 0; k < int(pr.size()); ++k)
                if (v[j] % pr[k] == 0)
                {
                    vc[j].pb(pr[k]);
                    cnt[j].pb(0);
                    while(v[j] % pr[k] == 0)
                    {
                        cnt[j].back()++;
                        v[j] /= pr[k];
                    }
//                    cerr << pr[k] << '\n';
                }
        int uk = 0;
        for(int j = 0; j < int(cnt[0].size()); ++j)
        {
            while(uk < int(cnt[1].size()) && vc[1][uk] <= vc[0][j])
            {
                if (vc[1][uk] == vc[0][j])
                {
                    if(cnt[0][j] > cnt[1][uk])
                        res[0].pb(cnt[0][j] - cnt[1][uk]);
                    else
                        res[1].pb(cnt[1][uk] - cnt[0][j]);
                }
                else
                    res[1].pb(cnt[1][uk]);
                ++uk;
            }
            if (!(uk > 0 && vc[1][uk - 1] == vc[0][j]))
                res[0].pb(cnt[0][j]);
        }
        while(uk < int(cnt[1].size()))
        {
            res[1].pb(cnt[1][uk]);
            ++uk;
        }
        int sum[2];
        sum[0] = 0;
        sum[1] = 0;
        ll ans = 1;
        for(int j = 0; j < 2; ++j)
            for(int k = 0; k < int(res[j].size()); ++k)
            {
                sum[j] += res[j][k];
                ans *= f_obr[res[j][k]];
                ans %= mod;
            }
//        cerr << sum[0] << ' ' << sum[1] << endl;
        ans *= f[sum[0]];
        ans %= mod;
        ans *= f[sum[1]];
        ans %= mod;
        cout << ans << '\n';
    }
	return 0;
}

//288807105787200
//1
//46 482955026400


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define F first
#define S second
#define pb push_back
#define sqr(x) (x) * (x)

using namespace std;

//mt19937_64 gen(time(0));
const ll mod = 998244353;
//const int inf = 1e9 + 45522;

ll binpow (ll a, ll n)
{
	if (n == 0)
		return 1;
	if (n % 2 == 1)
    {
		return (binpow(a, n - 1) * a) % mod;;
    }
	else
    {
		ll b = binpow(a, n / 2);
		return (b * b) % mod;
	}
}

ll f[500];
ll f_obr[500];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
#endif
    f[0] = 1;
    f_obr[0] = 1;
    for(ll i = 1; i < 500; ++i)
    {
        f[i] = f[i - 1] * i;
        f[i] %= mod;
        f_obr[i] = binpow(f[i], mod - 2);
    }

    ll d;
    cin >> d;
    vector <ll> pr;
    pr.reserve(500);
    for(ll i = 2; i * i <= d; ++i)
    {
        if (d % i == 0)
        {
            pr.pb(i);
            while(d % i == 0) d /= i;
        }
    }
    if (d > 1) pr.pb(d);
    int q;
    cin >> q;
    for(int i = 0; i < q; ++i)
    {
        ll v[2];
        cin >> v[0] >> v[1];
        vector <ll> vc[2];
        vector <int> cnt[2];
        for(int j = 0; j < 2; ++j)
            for(int k = 0; k < int(pr.size()); ++k)
                if (v[j] % pr[k] == 0)
                {
                    vc[j].pb(pr[k]);
                    cnt[j].pb(0);
                    while(v[j] % pr[k] == 0)
                    {
                        cnt[j].back()++;
                        v[j] /= pr[k];
                    }
//                    cerr << pr[k] << '\n';
                }
        int uk = 0;
        vector <int> res[2];
        for(int j = 0; j < int(cnt[0].size()); ++j)
        {
            while(uk < int(cnt[1].size()) && vc[1][uk] <= vc[0][j])
            {
                if (vc[1][uk] == vc[0][j])
                {
                    if(cnt[0][j] > cnt[1][uk])
                        res[0].pb(cnt[0][j] - cnt[1][uk]);
                    else
                        res[1].pb(cnt[1][uk] - cnt[0][j]);
                }
                else
                    res[1].pb(cnt[1][uk]);
                ++uk;
            }
            if (!(uk > 0 && vc[1][uk - 1] == vc[0][j]))
                res[0].pb(cnt[0][j]);
        }
        while(uk < int(cnt[1].size()))
        {
            res[1].pb(cnt[1][uk]);
            ++uk;
        }
        int sum[2];
        sum[0] = 0;
        sum[1] = 0;
        ll ans = 1;
        for(int j = 0; j < 2; ++j)
            for(int k = 0; k < int(res[j].size()); ++k)
            {
                sum[j] += res[j][k];
                ans *= f_obr[res[j][k]];
                ans %= mod;
            }
//        cerr << sum[0] << ' ' << sum[1] << endl;
        ans *= f[sum[0]];
        ans %= mod;
        ans *= f[sum[1]];
        ans %= mod;
        cout << ans << '\n';
    }
	return 0;
}

//288807105787200
//1
//46 482955026400


#include <iostream>
#include <vector>
#include <map>

using namespace std;
int mod=998244353;
vector <int> d(50,0);
vector <vector <int>> F(50, d);

int fak(int n,int k)
{
    if (F[n][k]>0)
    {
        return F[n][k];
    }
    if (n-k<k)
    {
        k=n-k;
    }
    if (k==0)
    {
        return 1;
    }
    if (k==1)
    {
        return n%mod;
    }
    return (fak(n-1,k)+fak(n-1,k-1))%mod;
}
vector <int> prime(int n)
{
    vector<int> P(n+1,1);
    vector <int> Q;
    P[0]=0;
    P[1]=0;
    int i=2;
    while (i*i<=n)
    {
        if (P[i]==1)
        {
            for (int j=i; j<=n/i; j++)
            {
                P[i*j]=0;
            }
        }
        i++;
    }
    for (int i=2; i<=n; i++)
    {
        if (P[i]==1)
        {
            Q.push_back(i);
        }
    }
    return Q;
}

long long int solve (long long int u, long long int v, vector <long long int> &Q)
{
    if (u==v)
    {
        return 1;
    }
    vector <int> A;
    vector <int> B;
    int j=0;
    int n=0;
    int m=0;
    long long int ats=1;
    while ((u>1 || v>1) && (j<Q.size()))
    {
        //cout<<u<<" "<<v<<" "<<j<<" "<<P.size()<<endl;
        int i=Q[j];
        if (u%i==0 || v%i==0)
        {
            int a=0;
            int b=0;
            while (u%i==0)
            {
                a++;
                u=u/i;
            }
            while (v%i==0)
            {
                b++;
                v=v/i;
            }
            if (a>b)
            {
                A.push_back(a-b);
                n=n+a-b;
            }
            if (a<b)
            {
                B.push_back(b-a);
                m=m+b-a;
            }
        }
        j++;
    }
    if ((u>1 || v>1) && j==Q.size() && u!=v)
    {
        if (u>1)
        {
            A.push_back(1);
            n++;
            Q.insert(Q.begin()+1,u);
        }
        if (v>1)
        {
            B.push_back(1);
            m++;
            Q.insert(Q.begin()+1,v);
        }
    }
    for (int i=0; i<A.size(); i++)
    {
        ats=ats*fak(n,A[i]);
        ats=ats%mod;
        n=n-A[i];
    }
    for (int i=0; i<B.size(); i++)
    {
        ats=ats*fak(m,B[i]);
        ats=ats%mod;
        m=m-B[i];
    }
    return ats;
}

struct pora
{
    long long int u;
    long long int v;

    bool operator<(const pora& other) const {
    if (u==other.u) {return v<other.v;}
    else {return u<other.u;}
}

};

void print(vector <long long int> A) {
for (int i=0;i<A.size();i++) {cout<<A[i]<<" ";}
cout<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    for (int i=1; i<50; i++)
    {
        for (int j=1; j<i; j++)
        {
            F[i][j]=fak(i,j);
            F[i][i-j]=F[i][j];
        }
    }
    cin.tie(0);
    long long int D;
    cin>>D;
    int q;
    cin>>q;
    vector <int> P=prime(31622780);
    vector <long long int> Q;
    vector <long long int> K;
    for (int i=0; i<P.size(); i++)
    {
        if (D%P[i]==0)
        {
            int k=0;
            Q.push_back(P[i]);
            while (D%P[i]==0)
            {
                D=D/P[i];
                k++;
            }
            K.push_back(k);
        }
    }
    if (D>1)
    {
        Q.push_back(D);
        K.push_back(1);
    }
    int s=Q.size();

    map <pora, long long int> M;
    vector <long long int> Dal;
    Dal.push_back(1);
    for (int i=0; i<Q.size(); i++)
    {
        long long int p=Q[i];
        vector <long long int> Q1;
        Q1.push_back(1);
        long long int q1=1;
        for (int r=0; r<K[i]; r++)
        {
            q1=q1*p;
            Q1.push_back(q1);
        }
        vector <long long int> Dal1;
        for (int r=0; r<Dal.size(); r++)
        {
            for (int w=0; w<Q1.size(); w++)
            {
                Dal1.push_back(Dal[r]*Q1[w]);
            }
        }
        Dal.clear();
        for (int r=0; r<Dal1.size(); r++)
        {
            Dal.push_back(Dal1[r]);
        }
    }
    if (Dal.size()<1000) {
    for (int i=0; i<Dal.size(); i++)
    {
        M[{Dal[i],Dal[i]}]=1;
        for (int j=i+1; j<Dal.size(); j++)
        {
            M[{Dal[i],Dal[j]}]=solve(Dal[i],Dal[j],Q);
            M[{Dal[j],Dal[i]}]=M[{Dal[i],Dal[j]}];
        }
    }}
    for (int i=0; i<q; i++)
    {
        long long int u,v;
        cin>>u>>v;
        if (Dal.size()<1000) {
        cout<<M[{u,v}]<<endl;}
        else {cout<<solve(u,v,Q)<<endl;}
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;
int mod=998244353;

int fak(int n,int k)
{
    if (n-k<k)
    {
        k=n-k;
    }
    if (k==0)
    {
        return 1;
    }
    if (k==1)
    {
        return n%mod;
    }
    return (fak(n-1,k)+fak(n-1,k-1))%mod;
}

void solve (long long int u, long long int v)
{
    if (u==v)
    {
        cout<<1<<endl;
        return;
    }
    vector <int> A;
    vector <int> B;
    int i=2;
    int n=0;
    int m=0;
    long long int ats=1;
    while (u>1 || v>1)
    {
        if (u%i==0 || v%i==0)
        {
            int a=0;
            int b=0;
            while (u%i==0)
            {
                a++;
                u=u/i;
            }
            while (v%i==0)
            {
                b++;
                v=v/i;
            }
            if (a>b) {A.push_back(a-b); n=n+a-b;}
            if (a<b) {B.push_back(b-a);m=m+b-a;}
        }
        i++;
    }
    for (int i=0; i<A.size(); i++)
    {
        ats=ats*fak(n,A[i]);
        ats=ats%mod;
        n=n-A[i];
    }
        for (int i=0; i<B.size(); i++)
    {
        ats=ats*fak(m,B[i]);
        ats=ats%mod;
        m=m-B[i];
    }
    cout<<ats<<endl;
}

int main()
{
    long long int D;
    cin>>D;
    int q;
    cin>>q;
    for (int i=0; i<q; i++)
    {
        long long int u,v;
        cin>>u>>v;
        solve(u,v);
    }
    return 0;
}


#include <iostream>
#include <vector>
#include <map>

using namespace std;
int mod=998244353;
vector <int> d(50,0);
vector <vector <int>> F(50, d);

int fak(int n,int k)
{
    if (F[n][k]>0)
    {
        return F[n][k];
    }
    if (n-k<k)
    {
        k=n-k;
    }
    if (k==0)
    {
        return 1;
    }
    if (k==1)
    {
        return n%mod;
    }
    return (fak(n-1,k)+fak(n-1,k-1))%mod;
}
vector <int> prime(int n)
{
    vector<int> P(n+1,1);
    vector <int> Q;
    P[0]=0;
    P[1]=0;
    int i=2;
    while (i*i<=n)
    {
        if (P[i]==1)
        {
            for (int j=i; j<=n/i; j++)
            {
                P[i*j]=0;
            }
        }
        i++;
    }
    for (int i=2; i<=n; i++)
    {
        if (P[i]==1)
        {
            Q.push_back(i);
        }
    }
    return Q;
}

long long int solve (long long int u, long long int v, vector <long long int> &Q)
{
    if (u==v)
    {
        return 1;
    }
    vector <int> A;
    vector <int> B;
    int j=0;
    int n=0;
    int m=0;
    long long int ats=1;
    while ((u>1 || v>1) && (j<Q.size()))
    {
        //cout<<u<<" "<<v<<" "<<j<<" "<<P.size()<<endl;
        int i=Q[j];
        if (u%i==0 || v%i==0)
        {
            int a=0;
            int b=0;
            while (u%i==0)
            {
                a++;
                u=u/i;
            }
            while (v%i==0)
            {
                b++;
                v=v/i;
            }
            if (a>b)
            {
                A.push_back(a-b);
                n=n+a-b;
            }
            if (a<b)
            {
                B.push_back(b-a);
                m=m+b-a;
            }
        }
        j++;
    }
    if ((u>1 || v>1) && j==Q.size() && u!=v)
    {
        if (u>1)
        {
            A.push_back(1);
            n++;
            Q.insert(Q.begin()+1,u);
        }
        if (v>1)
        {
            B.push_back(1);
            m++;
            Q.insert(Q.begin()+1,v);
        }
    }
    for (int i=0; i<A.size(); i++)
    {
        ats=ats*fak(n,A[i]);
        ats=ats%mod;
        n=n-A[i];
    }
    for (int i=0; i<B.size(); i++)
    {
        ats=ats*fak(m,B[i]);
        ats=ats%mod;
        m=m-B[i];
    }
    return ats;
}

struct pora
{
    long long int u;
    long long int v;

    bool operator<(const pora& other) const {
    if (u==other.u) {return v<other.v;}
    else {return u<other.u;}
}

};

void print(vector <long long int> A) {
for (int i=0;i<A.size();i++) {cout<<A[i]<<" ";}
cout<<endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    for (int i=1; i<50; i++)
    {
        for (int j=1; j<i; j++)
        {
            F[i][j]=fak(i,j);
            F[i][i-j]=F[i][j];
        }
    }
    cin.tie(0);
    long long int D;
    cin>>D;
    int q;
    cin>>q;
    vector <int> P=prime(31622780);
    vector <long long int> Q;
    vector <long long int> K;
    for (int i=0; i<P.size(); i++)
    {
        if (D%P[i]==0)
        {
            int k=0;
            Q.push_back(P[i]);
            while (D%P[i]==0)
            {
                D=D/P[i];
                k++;
            }
            K.push_back(k);
        }
    }
    if (D>1)
    {
        Q.push_back(D);
    }
    int s=Q.size();
    map <pora, long long int> M;
    vector <long long int> Dal;
    Dal.push_back(1);
    for (int i=0; i<Q.size(); i++)
    {
        long long int p=Q[i];
        vector <long long int> Q1;
        Q1.push_back(1);
        long long int q1=1;
        for (int r=0; r<K[i]; r++)
        {
            q1=q1*p;
            Q1.push_back(q1);
        }
        vector <long long int> Dal1;
        for (int r=0; r<Dal.size(); r++)
        {
            for (int w=0; w<Q1.size(); w++)
            {
                Dal1.push_back(Dal[r]*Q1[w]);
            }
        }
        Dal.clear();
        for (int r=0; r<Dal1.size(); r++)
        {
            Dal.push_back(Dal1[r]);
        }
    }
    if (Dal.size()<1000) {
    for (int i=0; i<Dal.size(); i++)
    {
        M[{Dal[i],Dal[i]}]=1;
        for (int j=i+1; j<Dal.size(); j++)
        {
            M[{Dal[i],Dal[j]}]=solve(Dal[i],Dal[j],Q);
            M[{Dal[j],Dal[i]}]=M[{Dal[i],Dal[j]}];
        }
    }}
    for (int i=0; i<q; i++)
    {
        long long int u,v;
        cin>>u>>v;
        if (Dal.size()<1000) {
        cout<<M[{u,v}]<<endl;}
        else {cout<<solve(u,v,Q)<<endl;}
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;
int mod=998244353;
vector <int> d(50,0);
vector <vector <int>> F(50, d);

int fak(int n,int k)
{
    if (F[n][k]>0)
    {
        return F[n][k];
    }
    if (n-k<k)
    {
        k=n-k;
    }
    if (k==0)
    {
        return 1;
    }
    if (k==1)
    {
        return n%mod;
    }
    return (fak(n-1,k)+fak(n-1,k-1))%mod;
}
vector <int> prime(int n)
{
    vector<int> P(n+1,1);
    vector <int> Q;
    P[0]=0;
    P[1]=0;
    int i=2;
    while (i*i<=n)
    {
        if (P[i]==1)
        {
            Q.push_back(i);
            for (int j=i; j<=n/i; j++)
            {
                P[i*j]=0;
            }
        }
        i++;
    }
    return Q;
}

void solve (long long int u, long long int v, vector <int> &P)
{
    if (u==v)
    {
        cout<<1<<"\n";
        return;
    }
    vector <int> A;
    vector <int> B;
    int j=0;
    int n=0;
    int m=0;
    long long int ats=1;
    while ((u>1 || v>1) && (j<P.size()))
    {
        //cout<<u<<" "<<v<<endl;
        int i=P[j];
        if (u%i==0 || v%i==0)
        {
            int a=0;
            int b=0;
            while (u%i==0)
            {
                a++;
                u=u/i;
            }
            while (v%i==0)
            {
                b++;
                v=v/i;
            }
            if (a>b)
            {
                A.push_back(a-b);
                n=n+a-b;
            }
            if (a<b)
            {
                B.push_back(b-a);
                m=m+b-a;
            }
        }
        j++;
    }
    if ((u>1 || v>1) && j==P.size() && u!=v)
    {
        if (u>1)
        {
            A.push_back(1);
        }
        if (v>1)
        {
            B.push_back(1);
        }
    }
    for (int i=0; i<A.size(); i++)
    {
        ats=ats*fak(n,A[i]);
        ats=ats%mod;
        n=n-A[i];
    }
    for (int i=0; i<B.size(); i++)
    {
        ats=ats*fak(m,B[i]);
        ats=ats%mod;
        m=m-B[i];
    }
    cout<<ats<<"\n";
}

int main()
{
    for (int i=1; i<50; i++)
    {
        for (int j=1; j<i; j++)
        {
            F[i][j]=fak(i,j);
            F[i][i-j]=F[i][j];
        }
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long int D;
    cin>>D;
    int q;
    cin>>q;
    vector <int> P=prime(31622780);
    for (int i=0; i<q; i++)
    {
        long long int u,v;
        cin>>u>>v;
        solve(u,v,P);
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;
int mod=998244353;
vector <int> d(50,0);
vector <vector <int>> F(50, d);

int fak(int n,int k)
{
    if (F[n][k]>0)
    {
        return F[n][k];
    }
    if (n-k<k)
    {
        k=n-k;
    }
    if (k==0)
    {
        return 1;
    }
    if (k==1)
    {
        return n%mod;
    }
    return (fak(n-1,k)+fak(n-1,k-1))%mod;
}
vector <int> prime(int n)
{
    vector<int> P(n+1,1);
    vector <int> Q;
    P[0]=0;
    P[1]=0;
    int i=2;
    while (i*i<=n)
    {
        if (P[i]==1)
        {
            for (int j=i; j<=n/i; j++)
            {
                P[i*j]=0;
            }
        }
        i++;
    }
    for (int i=2;i<=n;i++) {
    if (P[i]==1) {Q.push_back(i);}
    }
    return Q;
}

void solve (long long int u, long long int v, vector <int> &Q)
{
    if (u==v)
    {
        cout<<1<<"\n";
        return;
    }
    vector <int> A;
    vector <int> B;
    int j=0;
    int n=0;
    int m=0;
    long long int ats=1;
    while ((u>1 || v>1) && (j<Q.size()))
    {
        //cout<<u<<" "<<v<<" "<<j<<" "<<P.size()<<endl;
        int i=Q[j];
        if (u%i==0 || v%i==0)
        {
            int a=0;
            int b=0;
            while (u%i==0)
            {
                a++;
                u=u/i;
            }
            while (v%i==0)
            {
                b++;
                v=v/i;
            }
            if (a>b)
            {
                A.push_back(a-b);
                n=n+a-b;
            }
            if (a<b)
            {
                B.push_back(b-a);
                m=m+b-a;
            }
        }
        j++;
    }
    if ((u>1 || v>1) && j==Q.size() && u!=v)
    {
        if (u>1)
        {
            A.push_back(1);
            n++;
        }
        if (v>1)
        {
            B.push_back(1);
            m++;
        }
    }
    for (int i=0; i<A.size(); i++)
    {
        ats=ats*fak(n,A[i]);
        ats=ats%mod;
        n=n-A[i];
    }
    for (int i=0; i<B.size(); i++)
    {
        ats=ats*fak(m,B[i]);
        ats=ats%mod;
        m=m-B[i];
    }
    cout<<ats<<"\n";
}

int main()
{
    for (int i=1; i<50; i++)
    {
        for (int j=1; j<i; j++)
        {
            F[i][j]=fak(i,j);
            F[i][i-j]=F[i][j];
        }
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long int D;
    cin>>D;
    int q;
    cin>>q;
    vector <int> Q=prime(31622780);
    for (int i=0; i<q; i++)
    {
        long long int u,v;
        cin>>u>>v;
        solve(u,v,Q);
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;
int mod=998244353;
vector <int> d(50,0);
vector <vector <int>> F(50, d);

int fak(int n,int k)
{
    if (F[n][k]>0) {return F[n][k];}
    if (n-k<k)
    {
        k=n-k;
    }
    if (k==0)
    {
        return 1;
    }
    if (k==1)
    {
        return n%mod;
    }
    return (fak(n-1,k)+fak(n-1,k-1))%mod;
}

void solve (long long int u, long long int v)
{
    if (u==v)
    {
        cout<<1<<"\n";
        return;
    }
    vector <int> A;
    vector <int> B;
    int i=2;
    int n=0;
    int m=0;
    long long int ats=1;
    while (u>1 || v>1)
    {
        if (u%i==0 || v%i==0)
        {
            int a=0;
            int b=0;
            while (u%i==0)
            {
                a++;
                u=u/i;
            }
            while (v%i==0)
            {
                b++;
                v=v/i;
            }
            if (a>b) {A.push_back(a-b); n=n+a-b;}
            if (a<b) {B.push_back(b-a);m=m+b-a;}
        }
        i++;
    }
    for (int i=0; i<A.size(); i++)
    {
        ats=ats*fak(n,A[i]);
        ats=ats%mod;
        n=n-A[i];
    }
        for (int i=0; i<B.size(); i++)
    {
        ats=ats*fak(m,B[i]);
        ats=ats%mod;
        m=m-B[i];
    }
    cout<<ats<<"\n";
}

int main()
{
for (int i=1;i<50;i++) {
for (int j=1;j<i;j++) {
F[i][j]=fak(i,j);
F[i][i-j]=F[i][j];
}
}
ios_base::sync_with_stdio(false); cin.tie(0);
    long long int D;
    cin>>D;
    int q;
    cin>>q;
    for (int i=0; i<q; i++)
    {
        long long int u,v;
        cin>>u>>v;
        solve(u,v);
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;
int mod=998244353;
vector <int> d(50,0);
vector <vector <int>> F(50, d);

int fak(int n,int k)
{
    if (F[n][k]>0)
    {
        return F[n][k];
    }
    if (n-k<k)
    {
        k=n-k;
    }
    if (k==0)
    {
        return 1;
    }
    if (k==1)
    {
        return n%mod;
    }
    return (fak(n-1,k)+fak(n-1,k-1))%mod;
}
vector <int> prime(int n)
{
    vector<int> P(n+1,1);
    vector <int> Q;
    P[0]=0;
    P[1]=0;
    int i=2;
    while (i*i<=n)
    {
        if (P[i]==1)
        {
            for (int j=i; j<=n/i; j++)
            {
                P[i*j]=0;
            }
        }
        i++;
    }
    for (int i=2;i<=n;i++) {
    if (P[i]==1) {Q.push_back(i);}
    }
    return Q;
}

void solve (long long int u, long long int v, vector <int> &Q)
{
    if (u==v)
    {
        cout<<1<<"\n";
        return;
    }
    vector <int> A;
    vector <int> B;
    int j=0;
    int n=0;
    int m=0;
    long long int ats=1;
    while ((u>1 || v>1) && (j<Q.size()))
    {
        //cout<<u<<" "<<v<<" "<<j<<" "<<P.size()<<endl;
        int i=Q[j];
        if (u%i==0 || v%i==0)
        {
            int a=0;
            int b=0;
            while (u%i==0)
            {
                a++;
                u=u/i;
            }
            while (v%i==0)
            {
                b++;
                v=v/i;
            }
            if (a>b)
            {
                A.push_back(a-b);
                n=n+a-b;
            }
            if (a<b)
            {
                B.push_back(b-a);
                m=m+b-a;
            }
        }
        j++;
    }
    if ((u>1 || v>1) && j==Q.size() && u!=v)
    {
        if (u>1)
        {
            A.push_back(1);
            n++;
            Q.insert(Q.begin()+1,u);
        }
        if (v>1)
        {
            B.push_back(1);
            m++;
            Q.insert(Q.begin()+1,v);
        }
    }
    for (int i=0; i<A.size(); i++)
    {
        ats=ats*fak(n,A[i]);
        ats=ats%mod;
        n=n-A[i];
    }
    for (int i=0; i<B.size(); i++)
    {
        ats=ats*fak(m,B[i]);
        ats=ats%mod;
        m=m-B[i];
    }
    cout<<ats<<"\n";
}

int main()
{ios_base::sync_with_stdio(false); cin.tie(0);
    for (int i=1; i<50; i++)
    {
        for (int j=1; j<i; j++)
        {
            F[i][j]=fak(i,j);
            F[i][i-j]=F[i][j];
        }
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long int D;
    cin>>D;
    int q;
    cin>>q;
    vector <int> P=prime(31622780);
    vector <int> Q;
    for (int i=0;i<P.size();i++) {
    if (D%P[i]==0) {
    Q.push_back(P[i]);
    while (D%P[i]==0) {D=D/P[i];}
    }
    }
    if (D>1) {Q.push_back(D);}
    for (int i=0; i<q; i++)
    {
        long long int u,v;
        cin>>u>>v;
        solve(u,v,Q);
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;
int mod=998244353;
vector <int> d(50,0);
vector <vector <int>> F(50, d);

int fak(int n,int k)
{
    if (F[n][k]>0)
    {
        return F[n][k];
    }
    if (n-k<k)
    {
        k=n-k;
    }
    if (k==0)
    {
        return 1;
    }
    if (k==1)
    {
        return n%mod;
    }
    return (fak(n-1,k)+fak(n-1,k-1))%mod;
}
vector <int> prime(int n)
{
    vector<int> P(n+1,1);
    vector <int> Q;
    P[0]=0;
    P[1]=0;
    int i=2;
    while (i*i<=n)
    {
        if (P[i]==1)
        {
            for (int j=i; j<=n/i; j++)
            {
                P[i*j]=0;
            }
        }
        i++;
    }
    for (int i=2;i<=n;i++) {
    if (P[i]==1) {Q.push_back(i);}
    }
    return Q;
}

void solve (long long int u, long long int v, vector <int> &Q)
{
    if (u==v)
    {
        cout<<1<<"\n";
        return;
    }
    vector <int> A;
    vector <int> B;
    int j=0;
    int n=0;
    int m=0;
    long long int ats=1;
    while ((u>1 || v>1) && (j<Q.size()))
    {
        //cout<<u<<" "<<v<<" "<<j<<" "<<P.size()<<endl;
        int i=Q[j];
        if (u%i==0 || v%i==0)
        {
            int a=0;
            int b=0;
            while (u%i==0)
            {
                a++;
                u=u/i;
            }
            while (v%i==0)
            {
                b++;
                v=v/i;
            }
            if (a>b)
            {
                A.push_back(a-b);
                n=n+a-b;
            }
            if (a<b)
            {
                B.push_back(b-a);
                m=m+b-a;
            }
        }
        j++;
    }
    if ((u>1 || v>1) && j==Q.size() && u!=v)
    {
        if (u>1)
        {
            A.push_back(1);
            n++;
            Q.insert(Q.begin()+1,u);
        }
        if (v>1)
        {
            B.push_back(1);
            m++;
            Q.insert(Q.begin()+1,v);
        }
    }
    for (int i=0; i<A.size(); i++)
    {
        ats=ats*fak(n,A[i]);
        ats=ats%mod;
        n=n-A[i];
    }
    for (int i=0; i<B.size(); i++)
    {
        ats=ats*fak(m,B[i]);
        ats=ats%mod;
        m=m-B[i];
    }
    cout<<ats<<"\n";
}

int main()
{
    for (int i=1; i<50; i++)
    {
        for (int j=1; j<i; j++)
        {
            F[i][j]=fak(i,j);
            F[i][i-j]=F[i][j];
        }
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long int D;
    cin>>D;
    int q;
    cin>>q;
    vector <int> Q=prime(31622780);
    for (int i=0; i<q; i++)
    {
        long long int u,v;
        cin>>u>>v;
        solve(u,v,Q);
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;
int mod=998244353;
vector <int> d(50,0);
vector <vector <int>> F(50, d);

int fak(int n,int k)
{
    if (F[n][k]>0)
    {
        return F[n][k];
    }
    if (n-k<k)
    {
        k=n-k;
    }
    if (k==0)
    {
        return 1;
    }
    if (k==1)
    {
        return n%mod;
    }
    return (fak(n-1,k)+fak(n-1,k-1))%mod;
}
vector <int> prime(int n)
{
    vector<int> P(n+1,1);
    vector <int> Q;
    P[0]=0;
    P[1]=0;
    int i=2;
    while (i*i<=n)
    {
        if (P[i]==1)
        {
            for (int j=i; j<=n/i; j++)
            {
                P[i*j]=0;
            }
        }
        i++;
    }
    for (int i=2;i<=n;i++) {
    if (P[i]==1) {Q.push_back(i);}
    }
    return Q;
}

void solve (long long int u, long long int v, vector <int> &Q)
{
    if (u==v)
    {
        cout<<1<<"\n";
        return;
    }
    vector <int> A;
    vector <int> B;
    int j=0;
    int n=0;
    int m=0;
    long long int ats=1;
    while ((u>1 || v>1) && (j<Q.size()))
    {
        //cout<<u<<" "<<v<<" "<<j<<" "<<P.size()<<endl;
        int i=Q[j];
        if (u%i==0 || v%i==0)
        {
            int a=0;
            int b=0;
            while (u%i==0)
            {
                a++;
                u=u/i;
            }
            while (v%i==0)
            {
                b++;
                v=v/i;
            }
            if (a>b)
            {
                A.push_back(a-b);
                n=n+a-b;
            }
            if (a<b)
            {
                B.push_back(b-a);
                m=m+b-a;
            }
        }
        j++;
    }
    if ((u>1 || v>1) && j==Q.size() && u!=v)
    {
        if (u>1)
        {
            A.push_back(1);
            n++;
            Q.insert(Q.begin()+1,u);
        }
        if (v>1)
        {
            B.push_back(1);
            m++;
            Q.insert(Q.begin()+1,v);
        }
    }
    for (int i=0; i<A.size(); i++)
    {
        ats=ats*fak(n,A[i]);
        ats=ats%mod;
        n=n-A[i];
    }
    for (int i=0; i<B.size(); i++)
    {
        ats=ats*fak(m,B[i]);
        ats=ats%mod;
        m=m-B[i];
    }
    cout<<ats<<"\n";
}

int main()
{ios_base::sync_with_stdio(false); cin.tie(0);
    for (int i=1; i<50; i++)
    {
        for (int j=1; j<i; j++)
        {
            F[i][j]=fak(i,j);
            F[i][i-j]=F[i][j];
        }
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long int D;
    cin>>D;
    int q;
    cin>>q;
    vector <int> P=prime(31622780);
    vector <int> Q;
    for (int i=0;i<P.size();i++) {
    if (D%P[i]==0) {
    Q.push_back(P[i]);
    while (D%P[i]==0) {D=D/P[i];}
    }
    }
    if (D>1) {Q.push_back(D);}
    int s=Q.size();
    for (int i=0; i<q; i++)
    {
        long long int u,v;
        cin>>u>>v;
        if (s==1) {cout<<1<<"\n";}
        else {
        solve(u,v,Q);}
    }
    return 0;
}


#include <iostream>
#include <vector>

using namespace std;
int mod=998244353;
vector <int> d(50,0);
vector <vector <int>> F(50, d);

int fak(int n,int k)
{
    if (F[n][k]>0)
    {
        return F[n][k];
    }
    if (n-k<k)
    {
        k=n-k;
    }
    if (k==0)
    {
        return 1;
    }
    if (k==1)
    {
        return n%mod;
    }
    return (fak(n-1,k)+fak(n-1,k-1))%mod;
}
vector <int> prime(int n)
{
    vector<int> P(n+1,1);
    vector <int> Q;
    P[0]=0;
    P[1]=0;
    int i=2;
    while (i*i<=n)
    {
        if (P[i]==1)
        {
            for (int j=i; j<=n/i; j++)
            {
                P[i*j]=0;
            }
        }
        i++;
    }
    for (int i=2;i<=n;i++) {
    if (P[i]==1) {Q.push_back(i);}
    }
    return Q;
}

void solve (long long int u, long long int v, vector <int> &Q)
{
    if (u==v)
    {
        cout<<1<<"\n";
        return;
    }
    vector <int> A;
    vector <int> B;
    int j=0;
    int n=0;
    int m=0;
    long long int ats=1;
    while ((u>1 || v>1) && (j<Q.size()))
    {
        //cout<<u<<" "<<v<<" "<<j<<" "<<P.size()<<endl;
        int i=Q[j];
        if (u%i==0 || v%i==0)
        {
            int a=0;
            int b=0;
            while (u%i==0)
            {
                a++;
                u=u/i;
            }
            while (v%i==0)
            {
                b++;
                v=v/i;
            }
            if (a>b)
            {
                A.push_back(a-b);
                n=n+a-b;
            }
            if (a<b)
            {
                B.push_back(b-a);
                m=m+b-a;
            }
        }
        j++;
    }
    if ((u>1 || v>1) && j==Q.size() && u!=v)
    {
        if (u>1)
        {
            A.push_back(1);
            n++;
            Q.insert(Q.begin()+1,u);
        }
        if (v>1)
        {
            B.push_back(1);
            m++;
            Q.insert(Q.begin()+1,v);
        }
    }
    for (int i=0; i<A.size(); i++)
    {
        ats=ats*fak(n,A[i]);
        ats=ats%mod;
        n=n-A[i];
    }
    for (int i=0; i<B.size(); i++)
    {
        ats=ats*fak(m,B[i]);
        ats=ats%mod;
        m=m-B[i];
    }
    cout<<ats<<"\n";
}

int main()
{
    for (int i=1; i<50; i++)
    {
        for (int j=1; j<i; j++)
        {
            F[i][j]=fak(i,j);
            F[i][i-j]=F[i][j];
        }
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    long long int D;
    cin>>D;
    int q;
    cin>>q;
    vector <int> P=prime(31622780);
    vector <int> Q;
    for (int i=0;i<P.size();i++) {
    if (D%P[i]==0) {
    Q.push_back(P[i]);
    while (D%P[i]==0) {D=D/P[i];}
    }
    }
    if (D>1) {Q.push_back(D);}
    for (int i=0; i<q; i++)
    {
        long long int u,v;
        cin>>u>>v;
        solve(u,v,Q);
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef tuple<ll, ll, int> t3i;
typedef long double ld;

ll mod_mul(ll a, ll b, ll M) {
	ll ret = a * b - M * ll(ld(a) * ld(b) / ld(M));
	return ret + M * (ret < 0) - M * (ret >= (ll)M);
}

ll mod_pow(ll b, ll e, ll m) {
	ll ans = 1;
	for (; e; b = b * b % m, e /= 2)
		if (e & 1) ans = ans * b % m;
	return ans;
}

bool isPrime(ll n) {
	if (n < 2 || n % 6 % 4 != 1) return n - 2 < 2;
	ll A[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022},
	   s = __builtin_ctzll(n - 1), d = n >> s;
	trav(a, A) {
		ll p = mod_pow(a, d, n), i = s;
		while (p != 1 && p != n - 1 && a % n && i--) {
			p = mod_mul(p, p, n);
		}
		if (p != n - 1 && i != s) return 0;
	}
	return 1;
}

ll pollard(ll n) {
	auto f = [n](ll x) { return (mod_mul(x, x, n) + 1) % n; };
	if (!(n & 1)) return 2;
	for (ll i = 2;; i++) {
		ll x = i, y = f(x), p;
		while ((p = __gcd(n + y - x, n)) == 1)
			x = f(x), y = f(f(y));
		if (p != n) return p;
	}
}

vector<ll> factor(ll n) {
	if (n == 1) return {};
	if (isPrime(n)) return {n};
	ll x = pollard(n);
	auto l = factor(x), r = factor(n / x);
	l.insert(l.end(), all(r));
	return l;
}

vector<ll> factorial(1000000);
ll mod = 998244353ll;

ll solve(ll a, ll b) {
	auto factors = factor(a);
	map<ll, ll> a_count;
	trav(f, factors) a_count[f]++;

	factors = factor(b);
	map<ll, ll> b_count;
	trav(f, factors) b_count[f]++;

	vector<ll> factor_diff;
	ll tracker = 0;
	trav(cur, a_count) {
		ll diff = cur.second - b_count[cur.first];
		factor_diff.push_back(mod_pow(factorial[diff], mod - 2, mod));
		tracker += diff;
	}

	ll res = factorial[tracker];
	trav(inv, factor_diff) res = (res * inv) % mod;
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll D, q;
	cin >> D >> q;

	ll limit = 0;
	factorial[0] = factorial[1] = 1;
	rep(i, 2, sz(factorial)) factorial[i] = ((ll) i) * factorial[i - 1] % mod;

	rep(i, 0, q) {
		ll u, v;
		cin >> u >> v;
		ll g = __gcd(u, v);
		cout << (solve(u, g) * solve(v, g)) % mod << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef tuple<ll, ll, int> t3i;
typedef long double ld;

ll mod_mul(ll a, ll b, ll M) {
	ll ret = a * b - M * ll(ld(a) * ld(b) / ld(M));
	return ret + M * (ret < 0) - M * (ret >= (ll)M);
}

ll mod_pow(ll b, ll e, ll m) {
	ll ans = 1;
	for (; e; b = b * b % m, e /= 2)
		if (e & 1) ans = ans * b % m;
	return ans;
}

bool isPrime(ll n) {
	if (n < 2 || n % 6 % 4 != 1) return n - 2 < 2;
	ll A[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022},
	   s = __builtin_ctzll(n - 1), d = n >> s;
	trav(a, A) {
		ll p = mod_pow(a, d, n), i = s;
		while (p != 1 && p != n - 1 && a % n && i--) {
			p = mod_mul(p, p, n);
		}
		if (p != n - 1 && i != s) return 0;
	}
	return 1;
}

ll pollard(ll n) {
	auto f = [n](ll x) { return (mod_mul(x, x, n) + 1) % n; };
	if (!(n & 1)) return 2;
	for (ll i = 2;; i++) {
		ll x = i, y = f(x), p;
		while ((p = __gcd(n + y - x, n)) == 1)
			x = f(x), y = f(f(y));
		if (p != n) return p;
	}
}

vector<ll> factor(ll n) {
	if (n == 1) return {};
	if (isPrime(n)) return {n};
	ll x = pollard(n);
	auto l = factor(x), r = factor(n / x);
	l.insert(l.end(), all(r));
	return l;
}

vector<ll> fact(100);
vector<ll> inv_fact(100);
ll mod = 998244353ll;

vector<pair<ll, ll>> D_factors;
map<ll, pair<ll, ll>> nprime;

void calc(int pos, ll cur, ll prev, ll q) {
	if (pos == sz(D_factors)) {
		nprime[cur] = pair<ll, ll>(prev, q);
		return;
	}

	ll prime = D_factors[pos].first;
	ll quant = D_factors[pos].second;
	ll tracker = 1;
	rep(i, 0, quant + 1) {
		calc(pos + 1, tracker * cur, (i == 0 ? prev : tracker), (i == 0 ? q : i));
		tracker *= prime;
	}
}

ll solve(ll a, ll b) {
	ll c = a / b;
	ll tracker = 0;
	ll inv = 1;
	while(c > 1) {
		inv = (inv * inv_fact[nprime[c].second]) % mod;
		tracker += nprime[c].second;
		c /= nprime[c].first;
	}

	return (fact[tracker] * inv) % mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll D, q;
	cin >> D >> q;

	auto factors = factor(D);
	map<ll, ll> mp;
	trav(f, factors) mp[f]++;
	D_factors = vector<pair<ll, ll>>(all(mp));
	calc(0, 1, 1, 1);

	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	rep(i, 2, sz(fact)) {
		fact[i] = ((ll) i) * fact[i - 1] % mod;
		inv_fact[i] = mod_pow(fact[i], mod - 2, mod);
	}

	rep(i, 0, q) {
		ll u, v;
		cin >> u >> v;
		ll g = __gcd(u, v);
		cout << (solve(u, g) * solve(v, g)) % mod << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef tuple<ll, ll, int> t3i;
typedef long double ld;

ll mod_mul(ll a, ll b, ll M) {
	ll ret = a * b - M * ll(ld(a) * ld(b) / ld(M));
	return ret + M * (ret < 0) - M * (ret >= (ll)M);
}

ll mod_pow(ll b, ll e, ll m) {
	ll ans = 1;
	for (; e; b = b * b % m, e /= 2)
		if (e & 1) ans = ans * b % m;
	return ans;
}

bool isPrime(ll n) {
	if (n < 2 || n % 6 % 4 != 1) return n - 2 < 2;
	ll A[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022},
	   s = __builtin_ctzll(n - 1), d = n >> s;
	trav(a, A) {
		ll p = mod_pow(a, d, n), i = s;
		while (p != 1 && p != n - 1 && a % n && i--) {
			p = mod_mul(p, p, n);
		}
		if (p != n - 1 && i != s) return 0;
	}
	return 1;
}

ll pollard(ll n) {
	auto f = [n](ll x) { return (mod_mul(x, x, n) + 1) % n; };
	if (!(n & 1)) return 2;
	for (ll i = 2;; i++) {
		ll x = i, y = f(x), p;
		while ((p = __gcd(n + y - x, n)) == 1)
			x = f(x), y = f(f(y));
		if (p != n) return p;
	}
}

vector<ll> factor(ll n) {
	if (n == 1) return {};
	if (isPrime(n)) return {n};
	ll x = pollard(n);
	auto l = factor(x), r = factor(n / x);
	l.insert(l.end(), all(r));
	return l;
}

vector<ll> factorial(1000000);
ll mod = 998244353ll;

ll solve(ll a, ll b) {
	ll c = a / b;
	auto factors = factor(c);
	map<ll, ll> c_count;
	trav(f, factors) c_count[f]++;

	vector<ll> factor_diff;
	ll tracker = 0;
	trav(cur, c_count) {
		factor_diff.push_back(mod_pow(factorial[cur.second], mod - 2, mod));
		tracker += cur.second;
	}

	ll res = factorial[tracker];
	trav(inv, factor_diff) res = (res * inv) % mod;
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll D, q;
	cin >> D >> q;

	ll limit = 0;
	factorial[0] = factorial[1] = 1;
	rep(i, 2, sz(factorial)) factorial[i] = ((ll) i) * factorial[i - 1] % mod;

	rep(i, 0, q) {
		ll u, v;
		cin >> u >> v;
		ll g = __gcd(u, v);
		cout << (solve(u, g) * solve(v, g)) % mod << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

vector<ll> fact(100), inv_fact(100), factors;
const ll mod = 998244353ll;

ll mod_pow(ll b, ll e, ll m) {
	ll ans = 1;
	for (; e; b = b * b % m, e /= 2)
		if (e & 1) ans = ans * b % m;
	return ans;
}

void calc(ll n) {
	map<ll, ll> mp;
	for (ll i = 2; i * i <= n; i++) {
		if (n % i == 0) factors.push_back(i);
		while (n % i == 0) n /= i;
	}

	if (n > 1) factors.push_back(n);
}

ll solve(ll c) {
	ll tracker = 0;
	ll inv = 1;
	trav(f, factors) {
		int temp = 0;
		while (c % f == 0) {
			temp++;
			c /= f;
		}

		inv = inv * inv_fact[temp] % mod;
		tracker += temp;
	}

	return (fact[tracker] * inv) % mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll D, q;
	cin >> D >> q;

	calc(D);

	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	rep(i, 2, sz(fact)) {
		fact[i] = ((ll) i) * fact[i - 1] % mod;
		inv_fact[i] = mod_pow(fact[i], mod - 2, mod);
	}

	rep(i, 0, q) {
		ll u, v;
		cin >> u >> v;
		ll g = __gcd(u, v);
		cout << (solve(u / g) * solve(v / g)) % mod << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef tuple<ll, ll, int> t3i;
typedef long double ld;

ll mod_mul(ll a, ll b, ll M) {
	ll ret = a * b - M * ll(ld(a) * ld(b) / ld(M));
	return ret + M * (ret < 0) - M * (ret >= (ll)M);
}

ll mod_pow(ll b, ll e, ll m) {
	ll ans = 1;
	for (; e; b = b * b % m, e /= 2)
		if (e & 1) ans = ans * b % m;
	return ans;
}

bool isPrime(ll n) {
	if (n < 2 || n % 6 % 4 != 1) return n - 2 < 2;
	ll A[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022},
	   s = __builtin_ctzll(n - 1), d = n >> s;
	trav(a, A) {
		ll p = mod_pow(a, d, n), i = s;
		while (p != 1 && p != n - 1 && a % n && i--) {
			p = mod_mul(p, p, n);
		}
		if (p != n - 1 && i != s) return 0;
	}
	return 1;
}

ll pollard(ll n) {
	auto f = [n](ll x) { return (mod_mul(x, x, n) + 1) % n; };
	if (!(n & 1)) return 2;
	for (ll i = 2;; i++) {
		ll x = i, y = f(x), p;
		while ((p = __gcd(n + y - x, n)) == 1)
			x = f(x), y = f(f(y));
		if (p != n) return p;
	}
}

vector<ll> factor(ll n) {
	if (n == 1) return {};
	if (isPrime(n)) return {n};
	ll x = pollard(n);
	auto l = factor(x), r = factor(n / x);
	l.insert(l.end(), all(r));
	return l;
}

vector<ll> factorial(1000000);
ll mod = 998244353ll;

set<ll> D_factors;

ll solve(ll a, ll b) {
	ll c = a / b;
	ll tracker = 0;
	vector<ll> factor_diff;
	trav(f, D_factors) {
		ll temp = 0;
		for (; c % f == 0; c /= f, temp++);
		factor_diff.push_back(mod_pow(factorial[temp], mod - 2, mod));
		tracker += temp;
	}

	ll res = factorial[tracker];
	trav(inv, factor_diff) res = (res * inv) % mod;
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll D, q;
	cin >> D >> q;

	auto factors = factor(D);
	trav(f, factors) D_factors.insert(f);

	ll limit = 0;
	factorial[0] = factorial[1] = 1;
	rep(i, 2, sz(factorial)) factorial[i] = ((ll) i) * factorial[i - 1] % mod;

	rep(i, 0, q) {
		ll u, v;
		cin >> u >> v;
		ll g = __gcd(u, v);
		cout << (solve(u, g) * solve(v, g)) % mod << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef tuple<ll, ll, int> t3i;
typedef long double ld;

ll mod_mul(ll a, ll b, ll M) {
	ll ret = a * b - M * ll(ld(a) * ld(b) / ld(M));
	return ret + M * (ret < 0) - M * (ret >= (ll)M);
}

ll mod_pow(ll b, ll e, ll m) {
	ll ans = 1;
	for (; e; b = mod_mul(b, b, m), e /= 2)
		if (e & 1) ans = mod_mul(ans, b, m);
	return ans;
}

bool isPrime(ll n) {
	if (n < 2 || n % 6 % 4 != 1) return n - 2 < 2;
	ll A[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022},
	   s = __builtin_ctzll(n - 1), d = n >> s;
	trav(a, A) {
		ll p = mod_pow(a, d, n), i = s;
		while (p != 1 && p != n - 1 && a % n && i--) {
			p = mod_mul(p, p, n);
		}
		if (p != n - 1 && i != s) return 0;
	}
	return 1;
}

ll pollard(ll n) {
	auto f = [n](ll x) { return (mod_mul(x, x, n) + 1) % n; };
	if (!(n & 1)) return 2;
	for (ll i = 2;; i++) {
		ll x = i, y = f(x), p;
		while ((p = __gcd(n + y - x, n)) == 1) {
			x = f(x), y = f(f(y));
		}
		if (p != n) return p;
	}
}

vector<ll> factor(ll n) {
	if (n == 1) return {};
	if (isPrime(n)) {
		return {n};
	}
	return {n};
	ll x = pollard(n);
	auto l = factor(x), r = factor(n / x);
	l.insert(l.end(), all(r));
	return l;
}

vector<ll> fact(100);
vector<ll> inv_fact(100);
ll mod = 998244353ll;

vector<pair<ll, ll>> D_factors;
map<ll, pair<ll, ll>> nprime;

void calc(int pos, ll cur, ll prev, ll q) {
	if (pos == sz(D_factors)) {
		nprime[cur] = pair<ll, ll>(prev, q);
		return;
	}

	ll prime = D_factors[pos].first;
	ll quant = D_factors[pos].second;
	ll tracker = 1;
	rep(i, 0, quant + 1) {
		calc(pos + 1, tracker * cur, (i == 0 ? prev : tracker), (i == 0 ? q : i));
		tracker *= prime;
	}
}

ll solve(ll a, ll b) {
	ll c = a / b;
	ll tracker = 0;
	ll inv = 1;
	while(c > 1) {
		inv = (inv * inv_fact[nprime[c].second]) % mod;
		tracker += nprime[c].second;
		c /= nprime[c].first;
	}

	return (fact[tracker] * inv) % mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll D, q;
	cin >> D >> q;

	auto factors = factor(D);
	map<ll, ll> mp;
	trav(f, factors) mp[f]++;
	D_factors = vector<pair<ll, ll>>(all(mp));
	calc(0, 1, 1, 1);

	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	rep(i, 2, sz(fact)) {
		fact[i] = ((ll) i) * fact[i - 1] % mod;
		inv_fact[i] = mod_pow(fact[i], mod - 2, mod);
	}

	rep(i, 0, q) {
		ll u, v;
		cin >> u >> v;
		ll g = __gcd(u, v);
		cout << (solve(u, g) * solve(v, g)) % mod << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef tuple<ll, ll, int> t3i;
typedef long double ld;

ll mod_mul(ll a, ll b, ll M) {
	ll ret = a * b - M * ll(ld(a) * ld(b) / ld(M));
	return ret + M * (ret < 0) - M * (ret >= (ll)M);
}

ll mod_pow(ll b, ll e, ll m) {
	ll ans = 1;
	for (; e; b = mod_mul(b, b, m), e /= 2)
		if (e & 1) ans = mod_mul(ans, b, m);
	return ans;
}

bool isPrime(ll n) {
	if (n < 2 || n % 6 % 4 != 1) return n - 2 < 2;
	ll A[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022},
	   s = __builtin_ctzll(n - 1), d = n >> s;
	trav(a, A) {
		ll p = mod_pow(a, d, n), i = s;
		while (p != 1 && p != n - 1 && a % n && i--) {
			p = mod_mul(p, p, n);
		}
		if (p != n - 1 && i != s) return 0;
	}
	return 1;
}

ll pollard(ll n) {
	auto f = [n](ll x) { return (mod_mul(x, x, n) + 1) % n; };
	if (!(n & 1)) return 2;
	for (ll i = 2;; i++) {
		ll x = i, y = f(x), p;
		while ((p = __gcd(n + y - x, n)) == 1) {
			x = f(x), y = f(f(y));
		}
		if (p != n) return p;
	}
}

vector<ll> factor(ll n) {
	if (n == 1) return {};
	if (isPrime(n)) return {n};
	ll x = pollard(n);
	auto l = factor(x), r = factor(n / x);
	l.insert(l.end(), all(r));
	return l;
}

vector<ll> fact(100);
vector<ll> inv_fact(100);
ll mod = 998244353ll;

vector<pair<ll, ll>> D_factors;
map<ll, pair<ll, ll>> nprime;

void calc(int pos, ll cur, ll prev, ll q) {
	if (pos == sz(D_factors)) {
		nprime[cur] = pair<ll, ll>(prev, q);
		return;
	}

	ll prime = D_factors[pos].first;
	ll quant = D_factors[pos].second;
	ll tracker = 1;
	rep(i, 0, quant + 1) {
		calc(pos + 1, tracker * cur, (i == 0 ? prev : tracker), (i == 0 ? q : i));
		tracker *= prime;
	}
}

ll solve(ll a, ll b) {
	ll c = a / b;
	ll tracker = 0;
	ll inv = 1;
	while(c > 1) {
		inv = (inv * inv_fact[nprime[c].second]) % mod;
		tracker += nprime[c].second;
		c /= nprime[c].first;
	}

	return (fact[tracker] * inv) % mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll D, q;
	cin >> D >> q;

	auto factors = factor(D);
	map<ll, ll> mp;
	trav(f, factors) mp[f]++;
	D_factors = vector<pair<ll, ll>>(all(mp));
	calc(0, 1, 1, 1);

	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	rep(i, 2, sz(fact)) {
		fact[i] = ((ll) i) * fact[i - 1] % mod;
		inv_fact[i] = mod_pow(fact[i], mod - 2, mod);
	}

	rep(i, 0, q) {
		ll u, v;
		cin >> u >> v;
		ll g = __gcd(u, v);
		cout << (solve(u, g) * solve(v, g)) % mod << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;

vector<ll> fact(100), inv_fact(100), factors;
const ll mod = 998244353ll;

ll mod_pow(ll b, ll e, ll m) {
	ll ans = 1;
	for (; e; b = b * b % m, e /= 2)
		if (e & 1) ans = ans * b % m;
	return ans;
}

void calc(ll n) {
	map<ll, ll> mp;
	for (ll i = 2; i * i <= n; i++) {
		factors.push_back(i);
		while (n % i == 0) n /= i;
	}

	if (n > 1) factors.push_back(n);
}

ll solve(ll c) {
	ll tracker = 0;
	ll inv = 1;
	trav(f, factors) {
		int temp = 0;
		while (c % f == 0) {
			temp++;
			c /= f;
		}

		inv = inv * inv_fact[temp] % mod;
		tracker += temp;
	}

	return (fact[tracker] * inv) % mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll D, q;
	cin >> D >> q;

	calc(D);

	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	rep(i, 2, sz(fact)) {
		fact[i] = ((ll) i) * fact[i - 1] % mod;
		inv_fact[i] = mod_pow(fact[i], mod - 2, mod);
	}

	rep(i, 0, q) {
		ll u, v;
		cin >> u >> v;
		ll g = __gcd(u, v);
		cout << (solve(u / g) * solve(v / g)) % mod << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef tuple<ll, ll, int> t3i;
typedef long double ld;

ll mod_mul(ll a, ll b, ll M) {
	ll ret = a * b - M * ll(ld(a) * ld(b) / ld(M));
	return ret + M * (ret < 0) - M * (ret >= (ll)M);
}

ll mod_pow(ll b, ll e, ll m) {
	ll ans = 1;
	for (; e; b = b * b % m, e /= 2)
		if (e & 1) ans = ans * b % m;
	return ans;
}

bool isPrime(ll n) {
	if (n < 2 || n % 6 % 4 != 1) return n - 2 < 2;
	ll A[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022},
	   s = __builtin_ctzll(n - 1), d = n >> s;
	trav(a, A) {
		ll p = mod_pow(a, d, n), i = s;
		while (p != 1 && p != n - 1 && a % n && i--) {
			p = mod_mul(p, p, n);
		}
		if (p != n - 1 && i != s) return 0;
	}
	return 1;
}

ll pollard(ll n) {
	auto f = [n](ll x) { return (mod_mul(x, x, n) + 1) % n; };
	if (!(n & 1)) return 2;
	for (ll i = 2;; i++) {
		ll x = i, y = f(x), p;
		while ((p = __gcd(n + y - x, n)) == 1)
			x = f(x), y = f(f(y));
		if (p != n) return p;
	}
}

vector<ll> factor(ll n) {
	if (n == 1) return {};
	if (isPrime(n)) return {n};
	ll x = pollard(n);
	auto l = factor(x), r = factor(n / x);
	l.insert(l.end(), all(r));
	return l;
}

vector<ll> fact(1000);
vector<ll> inv_fact(1000);
ll mod = 998244353ll;

vector<pair<ll, ll>> D_factors;
map<ll, pair<ll, ll>> nprime;

void calc(int pos, ll cur, ll prev, ll q) {
	if (pos == sz(D_factors)) {
		nprime[cur] = pair<ll, ll>(prev, q);
		return;
	}

	ll prime = D_factors[pos].first;
	ll quant = D_factors[pos].second;
	ll tracker = 1;
	rep(i, 0, quant + 1) {
		calc(pos + 1, tracker * cur, (i == 0 ? prev : tracker), (i == 0 ? q : i));
		tracker *= prime;
	}
}

ll solve(ll a, ll b) {
	ll c = a / b;
	ll tracker = 0;
	ll inv = 1;
	while(c > 1) {
		ll temp = nprime[c].second;
		inv = (inv * inv_fact[nprime[c].second]) % mod;
		tracker += nprime[c].second;
		c /= nprime[c].first;
	}

	return fact[tracker] * inv;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll D, q;
	cin >> D >> q;

	auto factors = factor(D);
	map<ll, ll> mp;
	trav(f, factors) mp[f]++;
	D_factors = vector<pair<ll, ll>>(all(mp));
	calc(0, 1, 1, 1);

	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	rep(i, 2, sz(fact)) {
		fact[i] = ((ll) i) * fact[i - 1] % mod;
		inv_fact[i] = mod_pow(fact[i], mod - 2, mod);
	}

	rep(i, 0, q) {
		ll u, v;
		cin >> u >> v;
		ll g = __gcd(u, v);
		cout << (solve(u, g) * solve(v, g)) % mod << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef tuple<ll, ll, int> t3i;
typedef long double ld;

ll mod_mul(ll a, ll b, ll M) {
	ll ret = a * b - M * ll(ld(a) * ld(b) / ld(M));
	return ret + M * (ret < 0) - M * (ret >= (ll)M);
}

ll mod_pow(ll b, ll e, ll m) {
	ll ans = 1;
	for (; e; b = mod_mul(b, b, m), e /= 2)
		if (e & 1) ans = mod_mul(ans, b, m);
	return ans;
}

bool isPrime(ll n) {
	if (n < 2 || n % 6 % 4 != 1) return n - 2 < 2;
	ll A[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022},
	   s = __builtin_ctzll(n - 1), d = n >> s;
	trav(a, A) {
		ll p = mod_pow(a, d, n), i = s;
		while (p != 1 && p != n - 1 && a % n && i--) {
			p = mod_mul(p, p, n);
		}
		if (p != n - 1 && i != s) return 0;
	}
	return 1;
}

ll pollard(ll n) {
	auto f = [n](ll x) { return (mod_mul(x, x, n) + 1) % n; };
	if (!(n & 1)) return 2;
	for (ll i = 2;; i++) {
		ll x = i, y = f(x), p;
		while ((p = __gcd(n + y - x, n)) == 1) {
			x = f(x), y = f(f(y));
		}
		if (p != n) return p;
	}
}

vector<ll> factor(ll n) {
	if (n == 1) return {};
	if (isPrime(n)) return {n};
	ll x = pollard(n);
	auto l = factor(x), r = factor(n / x);
	l.insert(l.end(), all(r));
	return l;
}

vector<ll> fact(100);
vector<ll> inv_fact(100);
const ll mod = 998244353ll;

vector<pair<ll, ll>> D_factors;
map<ll, pair<ll, ll>> nprime;

void calc(int pos, ll cur, ll prev, ll q) {
	if (pos == sz(D_factors)) {
		nprime[cur] = pair<ll, ll>(prev, q);
		return;
	}

	ll prime = D_factors[pos].first;
	ll quant = D_factors[pos].second;
	ll tracker = 1;
	rep(i, 0, quant + 1) {
		calc(pos + 1, tracker * cur, (i == 0 ? prev : tracker), (i == 0 ? q : i));
		tracker *= prime;
	}
}

ll solve(ll a, ll b) {
	ll c = a / b;
	ll tracker = 0;
	ll inv = 1;
	while(c > 1) {
		inv = (inv * inv_fact[nprime[c].second]) % mod;
		tracker += nprime[c].second;
		c /= nprime[c].first;
	}

	return (fact[tracker] * inv) % mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll D, q;
	cin >> D >> q;

	auto factors = factor(D);
	map<ll, ll> mp;
	trav(f, factors) mp[f]++;
	D_factors = vector<pair<ll, ll>>(all(mp));
	calc(0, 1, 1, 1);

	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	rep(i, 2, sz(fact)) {
		fact[i] = ((ll) i) * fact[i - 1] % mod;
		inv_fact[i] = mod_pow(fact[i], mod - 2, mod);
	}

	rep(i, 0, q) {
		ll u, v;
		cin >> u >> v;
		ll g = __gcd(u, v);
		cout << (solve(u, g) * solve(v, g)) % mod << '\n';
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef tuple<ll, ll, int> t3i;
typedef long double ld;

ll mod_mul(ll a, ll b, ll M) {
	ll ret = a * b - M * ll(ld(a) * ld(b) / ld(M));
	return ret + M * (ret < 0) - M * (ret >= (ll)M);
}

ll mod_pow(ll b, ll e, ll m) {
	ll ans = 1;
	for (; e; b = mod_mul(b, b, m), e /= 2)
		if (e & 1) ans = mod_mul(ans, b, m);
	return ans;
}

bool isPrime(ll n) {
	if (n < 2 || n % 6 % 4 != 1) return n - 2 < 2;
	ll A[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022},
	   s = __builtin_ctzll(n - 1), d = n >> s;
	trav(a, A) {
		ll p = mod_pow(a, d, n), i = s;
		while (p != 1 && p != n - 1 && a % n && i--) {
			p = mod_mul(p, p, n);
		}
		if (p != n - 1 && i != s) return 0;
	}
	return 1;
}

ll pollard(ll n) {
	auto f = [n](ll x) { return (mod_mul(x, x, n) + 1) % n; };
	if (!(n & 1)) return 2;
	for (ll i = 2;; i++) {
		ll x = i, y = f(x), p;
		while ((p = __gcd(n + y - x, n)) == 1) {
			x = f(x), y = f(f(y));
		}
		if (p != n) return p;
	}
}

vector<ll> factor(ll n) {
	if (n == 1) return {};
	if (isPrime(n)) return {n};
	ll x = pollard(n);
	auto l = factor(x), r = factor(n / x);
	l.insert(l.end(), all(r));
	return l;
}

vector<ll> fact(100);
vector<ll> inv_fact(100);
ll mod = 998244353ll;

vector<pair<ll, ll>> D_factors;
map<ll, pair<ll, ll>> nprime;

void calc(int pos, ll cur, ll prev, ll q) {
	if (pos == sz(D_factors)) {
		nprime[cur] = pair<ll, ll>(prev, q);
		return;
	}

	ll prime = D_factors[pos].first;
	ll quant = D_factors[pos].second;
	ll tracker = 1;
	rep(i, 0, quant + 1) {
		calc(pos + 1, tracker * cur, (i == 0 ? prev : tracker), (i == 0 ? q : i));
		tracker *= prime;
	}
}

ll solve(ll a, ll b) {
	ll c = a / b;
	ll tracker = 0;
	ll inv = 1;
	while(c > 1) {
		inv = (inv * inv_fact[nprime[c].second]) % mod;
		tracker += nprime[c].second;
		c /= nprime[c].first;
	}

	return (fact[tracker] * inv) % mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll D, q;
	cin >> D >> q;

	auto factors = factor(D);
	map<ll, ll> mp;
	trav(f, factors) mp[f]++;
	D_factors = vector<pair<ll, ll>>(all(mp));
	calc(0, 1, 1, 1);

	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	rep(i, 2, sz(fact)) {
		fact[i] = ((ll) i) * fact[i - 1] % mod;
		inv_fact[i] = mod_pow(fact[i], mod - 2, mod);
	}

	rep(i, 0, q) {
		ll u, v;
		cin >> u >> v;
		ll g = __gcd(u, v);
		cout << (solve(u, g) * solve(v, g)) % mod << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef tuple<ll, ll, int> t3i;
typedef long double ld;

ll mod_mul(ll a, ll b, ll M) {
	ll ret = a * b - M * ll(ld(a) * ld(b) / ld(M));
	return ret + M * (ret < 0) - M * (ret >= (ll)M);
}

ll mod_pow(ll b, ll e, ll m) {
	ll ans = 1;
	for (; e; b = b * b % m, e /= 2)
		if (e & 1) ans = ans * b % m;
	return ans;
}

bool isPrime(ll n) {
	if (n < 2 || n % 6 % 4 != 1) return n - 2 < 2;
	ll A[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022},
	   s = __builtin_ctzll(n - 1), d = n >> s;
	trav(a, A) {
		ll p = mod_pow(a, d, n), i = s;
		while (p != 1 && p != n - 1 && a % n && i--) {
			p = mod_mul(p, p, n);
		}
		if (p != n - 1 && i != s) return 0;
	}
	return 1;
}

ll pollard(ll n) {
	auto f = [n](ll x) { return (mod_mul(x, x, n) + 1) % n; };
	if (!(n & 1)) return 2;
	for (ll i = 2;; i++) {
		ll x = i, y = f(x), p;
		while ((p = __gcd(n + y - x, n)) == 1)
			x = f(x), y = f(f(y));
		if (p != n) return p;
	}
}

vector<ll> factor(ll n) {
	if (n == 1) return {};
	if (isPrime(n)) return {n};
	ll x = pollard(n);
	auto l = factor(x), r = factor(n / x);
	l.insert(l.end(), all(r));
	return l;
}

vector<ll> fact(65);
vector<ll> inv_fact(65);
ll mod = 998244353ll;

vector<pair<ll, ll>> D_factors;
map<ll, pair<ll, ll>> nprime;

void calc(int pos, ll cur, ll prev, ll q) {
	if (pos == sz(D_factors)) {
		nprime[cur] = pair<ll, ll>(prev, q);
		return;
	}

	ll prime = D_factors[pos].first;
	ll quant = D_factors[pos].second;
	ll tracker = 1;
	rep(i, 0, quant + 1) {
		calc(pos + 1, tracker * cur, (i == 0 ? prev : tracker), (i == 0 ? q : i));
		tracker *= prime;
	}
}

ll solve(ll a, ll b) {
	ll c = a / b;
	ll tracker = 0;
	ll inv = 1;
	while(c > 1) {
		ll temp = nprime[c].second;
		inv = (inv * inv_fact[nprime[c].second]) % mod;
		tracker += nprime[c].second;
		c /= nprime[c].first;
	}

	return fact[tracker] * inv;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll D, q;
	cin >> D >> q;

	auto factors = factor(D);
	map<ll, ll> mp;
	trav(f, factors) mp[f]++;
	D_factors = vector<pair<ll, ll>>(all(mp));
	calc(0, 1, 1, 1);

	fact[0] = fact[1] = inv_fact[0] = inv_fact[1] = 1;
	rep(i, 2, sz(fact)) {
		fact[i] = ((ll) i) * fact[i - 1] % mod;
		inv_fact[i] = mod_pow(fact[i], mod - 2, mod);
	}

	rep(i, 0, q) {
		ll u, v;
		cin >> u >> v;
		ll g = __gcd(u, v);
		cout << (solve(u, g) * solve(v, g)) % mod << endl;
	}

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define rep(i, a, b) for (int i = a; i < (b); i++)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int) (x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef tuple<ll, ll, int> t3i;
typedef long double ld;

ll mod_mul(ll a, ll b, ll M) {
	ll ret = a * b - M * ll(ld(a) * ld(b) / ld(M));
	return ret + M * (ret < 0) - M * (ret >= (ll)M);
}

ll mod_pow(ll b, ll e, ll m) {
	ll ans = 1;
	for (; e; b = b * b % m, e /= 2)
		if (e & 1) ans = ans * b % m;
	return ans;
}

bool isPrime(ll n) {
	if (n < 2 || n % 6 % 4 != 1) return n - 2 < 2;
	ll A[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022},
	   s = __builtin_ctzll(n - 1), d = n >> s;
	trav(a, A) {
		ll p = mod_pow(a, d, n), i = s;
		while (p != 1 && p != n - 1 && a % n && i--) {
			p = mod_mul(p, p, n);
		}
		if (p != n - 1 && i != s) return 0;
	}
	return 1;
}

ll pollard(ll n) {
	auto f = [n](ll x) { return (mod_mul(x, x, n) + 1) % n; };
	if (!(n & 1)) return 2;
	for (ll i = 2;; i++) {
		ll x = i, y = f(x), p;
		while ((p = __gcd(n + y - x, n)) == 1)
			x = f(x), y = f(f(y));
		if (p != n) return p;
	}
}

vector<ll> factor(ll n) {
	if (n == 1) return {};
	if (isPrime(n)) return {n};
	ll x = pollard(n);
	auto l = factor(x), r = factor(n / x);
	l.insert(l.end(), all(r));
	return l;
}

vector<ll> factorial(1000000);
ll mod = 998244353ll;

vector<pair<ll, ll>> D_factors;
map<ll, pair<ll, ll>> nprime;

void calc(int pos, ll cur, ll prev, ll q) {
	if (pos == sz(D_factors)) {
		nprime[cur] = pair<ll, ll>(prev, q);
		return;
	}

	ll prime = D_factors[pos].first;
	ll quant = D_factors[pos].second;
	ll tracker = 1;
	rep(i, 0, quant + 1) {
		calc(pos + 1, tracker * cur, (i == 0 ? prev : tracker), (i == 0 ? q : i));
		tracker *= prime;
	}
}

ll solve(ll a, ll b) {
	ll c = a / b;
	ll tracker = 0;
	vector<ll> factor_diff;
	while(c > 1) {
		ll temp = nprime[c].second;
		factor_diff.push_back(mod_pow(factorial[temp], mod - 2, mod));
		tracker += temp;
		c /= nprime[c].first;
	}

	ll res = factorial[tracker];
	trav(inv, factor_diff) res = (res * inv) % mod;
	return res;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	ll D, q;
	cin >> D >> q;

	auto factors = factor(D);
	map<ll, ll> mp;
	trav(f, factors) mp[f]++;
	D_factors = vector<pair<ll, ll>>(all(mp));
	calc(0, 1, 1, 1);

	factorial[0] = factorial[1] = 1;
	rep(i, 2, sz(factorial)) factorial[i] = ((ll) i) * factorial[i - 1] % mod;

	rep(i, 0, q) {
		ll u, v;
		cin >> u >> v;
		ll g = __gcd(u, v);
		cout << (solve(u, g) * solve(v, g)) % mod << endl;
	}

	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=1e2;
ll fact[N];
vector<ll> dv;
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++;
    }
    if(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];
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()
{
  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);
    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>
#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=1e3;
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()
{
  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);
    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;
}