#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#define ll long long
using namespace std;
const int N=1e5+10,mod=998244353;
typedef pair<int,int> PII;
ll ksm(ll a,ll b)
{
ll ans=1,base=a,b1=b;
while(b1>0)
{
if(b1&1)
{
ans*=base;
ans%=mod;
}
b1>>=1;
base*=base;
base%=mod;
}
return ans;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
ll a1=0,b1=0,c,d;
cin>>a1>>b1;
while(cin>>c>>d)
{
if(!c&&!d) break;
b1+=d;
}
int q;
cin>>q;
while(q--)
{
ll x;
cin>>x;
if(x%a1==0)
{
ll s=b1-1;
while(x>1)
{
s--;
x/=a1;
}
if(s<-1) cout<<"0 ";
else if(s==-1) cout<<"1 ";
else cout<<ksm(2,s)<<' ';
}
else cout<<"0 ";
}
return 0;
}
到底哪里有问题啊,