import math def xgcd(a,b): prevx, nextx = 1, 0 prevy, nexty = 0, 1 while b: quotient = a//b nextx, prevx = prevx - quotient * nextx, nextx nexty, prevy = prevy - quotient * nexty, nexty a, b = b, a % b return prevx, prevy,a 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=xgcd(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)