import sys
base = {}
flag1 = True
flag2 = True
w_to_n = {}
for letter in "oqz":
w_to_n[letter] = 0
for letter in "ij":
w_to_n[letter] = 1
for letter in "abc":
w_to_n[letter] = 2
for letter in "def":
w_to_n[letter] = 3
for letter in "gh":
w_to_n[letter] = 4
for letter in "kl":
w_to_n[letter] = 5
for letter in "mn":
w_to_n[letter] = 6
for letter in "prs":
w_to_n[letter] = 7
for letter in "tuv":
w_to_n[letter] = 8
for letter in "wxy":
w_to_n[letter] = 9
def sorting(num, base):
sorted_by_lenth = []
sorted_by_order = []
sorted_base = sorted(base, key = len)[::-1]
newnum = num
def resort_by_lenth(newnum, sorted_base):
if sorted_base[0] in newnum:
sorted_by_lenth.append(sorted_base[0])
newnum_lst = list(newnum.partition(sorted_base[0]))
newnum_lst.pop(1)
newnum = "".join(newnum_lst)
sorted_base.pop(0)
if len(sorted_base) > 0 and newnum != "":
resort_by_lenth(newnum, sorted_base)
pass
resort_by_lenth(newnum, sorted_base)
def resort_by_order(num, sorted_by_lenth):
for _ in range(len(sorted_by_lenth)):
if num.partition(sorted_by_lenth[_])[0] == '':
num = num[len(sorted_by_lenth[_]):]
sorted_by_order.append(base[sorted_by_lenth[_]])
sorted_by_lenth.pop(_)
break
if len(sorted_by_lenth) > 0:
resort_by_order(num, sorted_by_lenth)
pass
resort_by_order(num, sorted_by_lenth)
if sorted_by_order != []:
print(" ".join(sorted_by_order))
else: print("No solution.")
pass
for line in sys.stdin:
if line == "-1" or line == "-1\n":
break
if flag1:
flag1 = False
num = line[:-1]
continue
if flag1 == False and flag2:
flag2 = False
counter = int(line)
continue
converted = ""
for _ in (line[:-1]):
converted += str(w_to_n[_])
base[converted] = line[:-1]
for letter in line[:-1]:
converted += str(w_to_n[letter])
counter -= 1
if counter <= 0:
flag1 = True
flag2 = True
sorting(num, base)
base = {}
aW1wb3J0IHN5cwoKYmFzZSA9IHt9CmZsYWcxID0gVHJ1ZQpmbGFnMiA9IFRydWUKd190b19uID0ge30KZm9yIGxldHRlciBpbiAib3F6IjoKICAgIHdfdG9fbltsZXR0ZXJdID0gMApmb3IgbGV0dGVyIGluICJpaiI6CiAgICB3X3RvX25bbGV0dGVyXSA9IDEKZm9yIGxldHRlciBpbiAiYWJjIjoKICAgIHdfdG9fbltsZXR0ZXJdID0gMgpmb3IgbGV0dGVyIGluICJkZWYiOgogICAgd190b19uW2xldHRlcl0gPSAzCmZvciBsZXR0ZXIgaW4gImdoIjoKICAgIHdfdG9fbltsZXR0ZXJdID0gNApmb3IgbGV0dGVyIGluICJrbCI6CiAgICB3X3RvX25bbGV0dGVyXSA9IDUKZm9yIGxldHRlciBpbiAibW4iOgogICAgd190b19uW2xldHRlcl0gPSA2CmZvciBsZXR0ZXIgaW4gInBycyI6CiAgICB3X3RvX25bbGV0dGVyXSA9IDcKZm9yIGxldHRlciBpbiAidHV2IjoKICAgIHdfdG9fbltsZXR0ZXJdID0gOApmb3IgbGV0dGVyIGluICJ3eHkiOgogICAgd190b19uW2xldHRlcl0gPSA5CgoKZGVmIHNvcnRpbmcobnVtLCBiYXNlKToKCiAgICBzb3J0ZWRfYnlfbGVudGggPSBbXQogICAgc29ydGVkX2J5X29yZGVyID0gW10KICAgIHNvcnRlZF9iYXNlID0gc29ydGVkKGJhc2UsIGtleSA9IGxlbilbOjotMV0KICAgIG5ld251bSA9IG51bQoKICAgIGRlZiByZXNvcnRfYnlfbGVudGgobmV3bnVtLCBzb3J0ZWRfYmFzZSk6CgogICAgICAgIGlmIHNvcnRlZF9iYXNlWzBdIGluIG5ld251bToKICAgICAgICAgICAgc29ydGVkX2J5X2xlbnRoLmFwcGVuZChzb3J0ZWRfYmFzZVswXSkKICAgICAgICAgICAgbmV3bnVtX2xzdCA9IGxpc3QobmV3bnVtLnBhcnRpdGlvbihzb3J0ZWRfYmFzZVswXSkpCiAgICAgICAgICAgIG5ld251bV9sc3QucG9wKDEpCiAgICAgICAgICAgIG5ld251bSA9ICIiLmpvaW4obmV3bnVtX2xzdCkKICAgICAgICBzb3J0ZWRfYmFzZS5wb3AoMCkKCiAgICAgICAgaWYgbGVuKHNvcnRlZF9iYXNlKSA+IDAgYW5kIG5ld251bSAhPSAiIjoKICAgICAgICAgICAgcmVzb3J0X2J5X2xlbnRoKG5ld251bSwgc29ydGVkX2Jhc2UpCiAgICAgICAgcGFzcwoKICAgIHJlc29ydF9ieV9sZW50aChuZXdudW0sIHNvcnRlZF9iYXNlKQoKICAgIGRlZiByZXNvcnRfYnlfb3JkZXIobnVtLCBzb3J0ZWRfYnlfbGVudGgpOgoKICAgICAgICBmb3IgXyBpbiByYW5nZShsZW4oc29ydGVkX2J5X2xlbnRoKSk6CiAgICAgICAgICAgIGlmIG51bS5wYXJ0aXRpb24oc29ydGVkX2J5X2xlbnRoW19dKVswXSA9PSAnJzoKICAgICAgICAgICAgICAgIG51bSA9IG51bVtsZW4oc29ydGVkX2J5X2xlbnRoW19dKTpdCiAgICAgICAgICAgICAgICBzb3J0ZWRfYnlfb3JkZXIuYXBwZW5kKGJhc2Vbc29ydGVkX2J5X2xlbnRoW19dXSkKICAgICAgICAgICAgICAgIHNvcnRlZF9ieV9sZW50aC5wb3AoXykKICAgICAgICAgICAgICAgIGJyZWFrCiAgICAgICAgaWYgbGVuKHNvcnRlZF9ieV9sZW50aCkgPiAwOgogICAgICAgICAgIHJlc29ydF9ieV9vcmRlcihudW0sIHNvcnRlZF9ieV9sZW50aCkKICAgICAgICBwYXNzCgogICAgcmVzb3J0X2J5X29yZGVyKG51bSwgc29ydGVkX2J5X2xlbnRoKQoKICAgIGlmIHNvcnRlZF9ieV9vcmRlciAhPSBbXToKICAgICAgICBwcmludCgiICIuam9pbihzb3J0ZWRfYnlfb3JkZXIpKQogICAgZWxzZTogcHJpbnQoIk5vIHNvbHV0aW9uLiIpCgogICAgcGFzcwoKCmZvciBsaW5lIGluIHN5cy5zdGRpbjoKICAgIGlmIGxpbmUgPT0gIi0xIiBvciBsaW5lID09ICItMVxuIjoKICAgICAgICBicmVhawogICAgaWYgZmxhZzE6CiAgICAgICAgZmxhZzEgPSBGYWxzZQogICAgICAgIG51bSA9IGxpbmVbOi0xXQogICAgICAgIGNvbnRpbnVlCiAgICBpZiBmbGFnMSA9PSBGYWxzZSBhbmQgZmxhZzI6CiAgICAgICAgZmxhZzIgPSBGYWxzZQogICAgICAgIGNvdW50ZXIgPSBpbnQobGluZSkKICAgICAgICBjb250aW51ZQogICAgY29udmVydGVkID0gIiIKICAgIGZvciBfIGluIChsaW5lWzotMV0pOgogICAgICAgIGNvbnZlcnRlZCArPSBzdHIod190b19uW19dKQogICAgYmFzZVtjb252ZXJ0ZWRdID0gbGluZVs6LTFdCiAgICBmb3IgbGV0dGVyIGluIGxpbmVbOi0xXToKICAgICAgICBjb252ZXJ0ZWQgKz0gc3RyKHdfdG9fbltsZXR0ZXJdKQogICAgY291bnRlciAtPSAxCiAgICBpZiBjb3VudGVyIDw9IDA6CiAgICAgICAgZmxhZzEgPSBUcnVlCiAgICAgICAgZmxhZzIgPSBUcnVlCiAgICAgICAgc29ydGluZyhudW0sIGJhc2UpCiAgICAgICAgYmFzZSA9IHt9Cg==