import math N = int(input()) S, T = input().split() s, t = len(S), len(T) A = list(map(int, input().split())) def abm(a, b, m): d = math.gcd(a, b, m) a //= d b //= d m //= d #if math.gcd(a, m) != 1: # res = 'No Answer' #else: x = pow(a, -1, m)*b x %= m res = x return res # s, t は定数 def solve(a:int): # s*x + t*y == a を満たし、 # かつ x が最大になるような解を求める # mod s を取ると # t*y ≡ a (mod s) を解く y = abm(t, a, s) x = (a - t*y)//s return x, y for a in A: x, y = solve(a) #print(x, y) memo = [S]*x + [T]*y print(*memo)