positions_old = {}
positions_new = {}
olds = []
news = []
q = int(input())
for vez in range(q):
old, new = input().split()
if old in positions_new:
position = positions_new[old]
news[position] = new
del positions_new[old]
positions_new[new] = position
else:
position = len(olds)
olds.append(old)
news.append(new)
positions_old[old] = position
positions_new[new] = position
num_users = len(olds)
print(num_users)
for position in range(num_users):
print(f'{olds[position]} {news[position]}')
727A - Transformation from A to B | 822B - Crossword solving |
1623A - Robot Cleaner | 884B - Japanese Crosswords Strike Back |
862B - Mahmoud and Ehab and the bipartiteness | 429A - Xor-tree |
1675C - Detective Task | 950A - Left-handers Right-handers and Ambidexters |
672B - Different is Good | 1C - Ancient Berland Circus |
721A - One-dimensional Japanese Crossword | 1715B - Beautiful Array |
60B - Serial Time | 453A - Little Pony and Expected Maximum |
1715A - Crossmarket | 1715C - Monoblock |
1512C - A-B Palindrome | 1679B - Stone Age Problem |
402A - Nuts | 792A - New Bus Route |
221A - Little Elephant and Function | 492C - Vanya and Exams |
1369B - AccurateLee | 892B - Wrath |
999A - Mishka and Contest | 727C - Guess the Array |
1625C - Road Optimization | 1715D - 2+ doors |
267A - Subtractions | 1582A - Luntik and Concerts |