#!/usr/bin/python3 def letter_to_int(c): return ord(c) - ord('A') def int_to_letter(i): return chr(ord('A') + i) def continue_from(o): global edges for i in range(26): if edges[o][i] != 0: edges[o][i] -= 1 return i return -1 # Neni kam pokracovat. def cycle_from(o): cycle = [] nextLetter = continue_from(o) while nextLetter != -1: cycle.append(nextLetter) nextLetter = continue_from(nextLetter) return cycle # Je to cyklus, jinde nez v o jsme nemohli skoncit. M = int(input()) # Vyrobime tabulku hran. cislo edges[i][j] znamena # cetnost hrany z i do j. edges = [[0 for i in range(26)] for j in range(26)] for i in range(M): line = input() vertices = line.split() u = vertices[0][0] # Prvni pismeno prvniho slova v = vertices[1][0] # Prvni pismeno druheho slova edges[letter_to_int(u)][letter_to_int(v)] += 1 # Najdeme pismeno, ze ktereho muzeme zacit. origin = 0 for i in range(26): if sum(edges[i]) != 0: origin = i break path = cycle_from(origin) for i in range(len(path)): u = path[i] while sum(edges[u]) != 0: expansion = cycle_from(u) path = path[:i+1] + expansion + path[i+1:] for i in range(M): print(int_to_letter(path[i-1]) + " " + int_to_letter(path[i]))