using System.Collections.Generic;
public static void Main()
string handleCountString = Console.ReadLine();
int handleCount = Int32.Parse(handleCountString);
var olds = new string[handleCount];
var news = new string[handleCount];
var map = new Dictionary<string, string>();
var rmap = new Dictionary<string, string>();
var used = new HashSet<string>();
var res = new Dictionary<string, string>();
for (int i = 0; i < handleCount; i++)
string handleInputString = Console.ReadLine();
string[] handleInputStringSplit = handleInputString.Split(' ');
olds[i] = handleInputStringSplit[0];
news[i] = handleInputStringSplit[1];
for (int i = 0; i < handleCount; i++)
if (used.Contains(olds[i]) || used.Contains(news[i]))
while (rmap.ContainsKey(olds[i]))
while (map.ContainsKey(news[i]))
Console.WriteLine(res.Count);
foreach (KeyValuePair<string, string> result in res)
Console.WriteLine(result.Key + " " + result.Value);