text = input().lower()
arr = text.split(' ')
arr.sort()
for x1 in arr:
for x2 in arr:
common_letters = len(set(x1) & set(x2))
if (len(x1) == len(x2) and (common_letters == len(x1)) and (x1 != x2)):
print(x1, x2)
arr.remove(x1)
arr.remove(x2)