import sympy import math n=int(input()) S,T=input().split() s=len(S);t=len(T) v=math.gcd(s,t) s//=v;t//=v u=math.lcm(s,t) a=list(map(int,input().split())) x,y,d=list(sympy.gcdex(s,t)) for i in range(n): a[i]//=v X=x*a[i];Y=y*a[i] w=Y//s Y%=s X+=w*t print((S+' ')*X+(T+' ')*Y)