from math import gcd N = int(input()) S, T = input().split() s, t = len(S), len(T) print(s, t) A = list(map(int, input().split())) MAX = 20 cnta = [-1] * (MAX + 1) for i in range(0, MAX + 1): if i % s == 0: cnta[i] = i // s cntb = [-1] * (MAX + 1) for i in range(MAX + 1): if cnta[i] == -1: if i - t < 0 or cntb[i - t] == -1: continue cntb[i] = cntb[i - t] + 1 else: cntb[i] = 0 for a in A: # a = xs+ytを解く y = cntb[a] x = cnta[a - y * t] for _ in range(x): print(S, end=" ") for _ in range(y): print(T, end=" ") print()