from itertools import permutations for names in permutations(sorted([input() for _ in range(int(input()))]), r=3): print(", ".join(names))