import sys
def dfs(flag):
if len(visit) == 6:
print(" ".join(map(str, visit)))
return
for i in range(flag, k):
if S[i] not in visit:
visit.append(S[i])
dfs(i)
visit.pop()
while True:
tmp = list(map(int, sys.stdin.readline()[:-1].split(' ')))
if tmp[0] == 0: break
else:
k = tmp[0]; S = tmp[1:]
visit = []
dfs(0)
print()