char a[105],b[1005],ans[1005];
int len1,len2,h=1,p;
int c[105];
using namespace std;
int main(){
// freopen...("vigenere.in","r",stdin);
//freopen("vigenere.out","w",stdout);
scanf("%s%s",a+1,b+1);
len1...("game.in","r",stdin);
//freopen("game.out","w",stdout);
cin>>n;
for(int i=0;i<=n;i++){
cin>>a[i...("mod.in","r",stdin);
// freopen("mod.out","w",stdout);
cin>>a>>b;
gcd(a,b,x,y);
x=(x%b+b...("classroom.in","r",stdin);
// freopen("classroom.out","w",stdout);
cin>>n>>m;
for(int i=1;i<=n;++