Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.

Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.


-----Input-----

The first line contains integer q (1 ≤ q ≤ 1000), the number of handle change requests.

Next q lines contain the descriptions of the requests, one per line.

Each query consists of two non-empty strings old and new, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings old and new are distinct. The lengths of the strings do not exceed 20.

The requests are given chronologically. In other words, by the moment of a query there is a single person with handle old, and handle new is not used and has not been used by anyone.


-----Output-----

In the first line output the integer n — the number of users that changed their handles at least once.

In the next n lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, old and new, separated by a space, meaning that before the user had handle old, and after all the requests are completed, his handle is new. You may output lines in any order.

Each user who changes the handle must occur exactly once in this description.


-----Examples-----
Input
5
Misha ILoveCodeforces
Vasya Petrov
Petrov VasyaPetrov123
ILoveCodeforces MikeMirzayanov
Petya Ivanov

Output
3
Petya Ivanov
Misha MikeMirzayanov
Vasya VasyaPetrov123

Difficulty: interview

Starter code:

Solutions:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

n = int(input())

b_a = {}
for n_ in range(n):
    b, a = input().split()

    replaced = False
    for k in b_a:
        if b_a[k] == b:
            b_a[k] = a
            replaced = True
    if not replaced:
        b_a[b] = a

print(len(b_a))
for k in b_a:
    print(k + " " + b_a[k])


q = int(input())
current = []
begin = []
for i in range(q):
    old, new = input().split()
    for ind in range(len(current)):
        if current[ind] == old:
            current[ind] = new
            break
    else:
        begin.append(old)
        current.append(new)
print(len(begin))
for el in zip(begin, current):
    print(el[0],el[1])


#/usr/bin/env python3

N = int(input())
names = [input().split() for i in range(N)]

c_to_old = dict()

for n in names:
    if n[0] not in c_to_old:
        c_to_old[n[1]] = n[0]
    else:
        old = c_to_old[n[0]]
        del c_to_old[n[0]]
        c_to_old[n[1]] = old

print(len(c_to_old))
thing = sorted(list(c_to_old.items()), key = lambda x: x[1])
for c, o in thing:
    print(o, c)


import sys

n = int(sys.stdin.readline())
tracker = {}
count = 0

for i in range(n):
	pair = sys.stdin.readline().split("\n")[0].split(" ")
	if (pair[0] in tracker):
		tracker[pair[1]] = tracker.pop(pair[0])
	else:
		count += 1
		tracker[pair[1]] = pair[0]
		
print(count)
for key in list(tracker.keys()):
	print(tracker[key] + " "+key)



def main():
    q = int(input())
    d = {}
    for _ in range(q):
        old, new = input().split()
        oldold = d.get(old)
        if oldold:
            del d[old]
            d[new] = oldold
        else:
            d[new] = old
    l = [str(len(d))]
    for k, v in d.items():
        l.append(' '.join((v, k)))
    print('\n'.join(l))


def __starting_point():
    main()
__starting_point()

def main():
	q = int(input())
	old = []
	new = []
	for _ in range(q):
		a, b = list(input().split())
		#print(a, b)
		flag = 1
		for i in range(len(new)):
			if new[i] == a:
				new[i] = b
				flag = 0
				break
		if flag == 1:
			old.append(a)
			new.append(b)
	n = len(old)
	print(n)
	for i in range(n):
		print(old[i], new[i])

def __starting_point():
	main()
__starting_point()

import math,string,itertools,fractions,heapq,collections,re,array,bisect
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict


def main2(n,old,new):
    orig = []
    visited = []

    o = []
    l = []

    for i,j in zip(old,new):
        if i not in visited:
            orig.append([i,j])
            visited.append(j)
        else:
            for k,v in enumerate(orig):
                if i == v[-1]:
                    orig[k].append(j)
                    visited.append(j)
                    continue
    print(len(orig))
    for v in orig:
        print(v[0]," ",v[-1])

def main(n,old,new):
    o = []
    l = []
    for i,j in zip(old,new):
        if i not in l:
            o.append(i)
            l.append(j)
        else:
            k = l.index(i)
            l[k] = j
    print(len(o))
    for x,y in zip(o,l):
        print(x,y)

def main_input(info=0):
    n = int(input())
    l,r = list(range(n)), list(range(n))
    for i in range(n):
        l[i],r[i] = input().split()
    main(n,l,r)

def __starting_point():
    main_input()

__starting_point()

q = int(input())
logs = [input().split() for _ in range(q)]
origin = []
now = []
cnt = 0
for old, new in logs:
    if old not in now:
        origin.append(old)
        now.append(new)
        cnt += 1
    else:
        now[now.index(old)] = new
print(cnt)
for i in range(len(now)):
    print(origin[i], now[i])


n=int(input())
queries=[]
names=[]
f=[]
l=[]
for i in range(n):
    queries.append(input().split(' '))
for i in range(n):
    for j in range(2):
        if queries[i][j] in names:
            if j==0:
                names.remove(queries[i][j])
                l[l.index(queries[i][j])]=queries[i][j-1]
        else:
            names.append(queries[i][j])
            if j==0:
                f.append(queries[i][j])
            else:
                if queries[i][j] not in l:
                    l.append(queries[i][j])
print(len(f))
for k in range(len(f)):
    print(f[k],l[k])


__author__ = 'Rakshak.R.Hegde'
"""
Created on Jan 12 2015 PM 02:41

@author: Rakshak.R.Hegde
"""

changes = []
valids = []
for t in range(int(input())):
    a, b = input().split()
    do = True
    for i in changes:
        if b == (i[0] or i[1]):
            do = False
            break
        if i[1] == a:
            i[1] = b
            break
    else:
        if do: changes.append([a, b])
print(len(changes))
for change in changes:
    print(change[0], change[1])

n = int(input())
p = []
q = []
c = 1
for i in range(n):
    a,b=list(map(str,input().split()))
    if a not in q:
        p.append([a,b])
        q.append(a)
        q.append(b)
    else:
        x = q.index(p[int(q.index(a)/2-.5)][1])
        p[int(q.index(a)/2-.5)][1]=b
        q[x]=b

print(len(p))
for i in range(len(p)):
    print(p[i][0], p[i][1])


def tabe(a,b):
    i=0
    while i<len(a):
        if b==a[i]:
            return i
        i=i+1
    return -1
a=int(input())
l=[]
ll=[]
i=0
while i<a:
    b=list(input().split())
    c=b[0]
    d=b[1]
    x=tabe(ll,c)
    if x==-1:
        l.append(c)
        ll.append(d)
    else:
        ll[x]=d
    i=i+1
i=0
print(len(l))
while i<len(l):
    print(l[i],ll[i])
    i=i+1


a=int(input())

old=[]
new=[]
d={}
for i in range(a):
    p=input().split()
    old.append(p[0])
    new.append(p[1])
    

dis=[]

for i in range(a):
    if old[i] not in new:
        dis.append(old[i])

print(len(dis))

for i in range(len(dis)):
    p=dis[i]
    q=dis[i]
    for j in range(a):
        if p==old[j]:
            p=new[j]
    s=q+" "+p
    print(s)

n = int(input())
d = []
for i in range(n):
    a, b = input().split()
    f = False
    for x in d:
        if a == x[1]:
            x[1] = b
            f = True
            break
    if not f:
        d.append([a, b])

print(len(d))
for x in d:
    print(x[0], x[1])


queries = []
for q in range(int(input())):
    old, new = input().split()
    done = False
    for elem in queries:
        if old == elem[-1]:
            elem.append(new)
            done = True
            break
    if not done:
        queries.append([old, new])
print(len(queries))
for elem in queries:
    print(elem[0], elem[-1])


inCount = int(input())
a = {}
for i in range(inCount):
    curStr1, curStr2 = input().split()
    if curStr1 not in a.keys():
        a[curStr2] = curStr1
    else:
        prevValue = a[curStr1]
        a.pop(curStr1)
        a[curStr2] = prevValue
print (len(a))
for key, value in a.items():
    print(value, key)

q = int(input())
dic = {}
for i in range(q):
	a,b = input().split()
	used = False
	for i in list(dic.keys()):
		if a == dic[i]:
			used = True
			dic[i] = b
	if not used:
		dic[a] = b

print(len(dic))
for i in list(dic.keys()):
	print(i,dic[i])


a = int(input())
sa = []
for i in range(a):
    x, y = map(str, input().split(' '))
    sa.append([x, y, 0])
for i in sa:
    if i[2] == 0:
        for j in sa:

            if j[2] == 0 and i[1] == j[0]:
                i[1] = j[1]
                j[2] = 2
        i[2] = 1
a = [i for i in sa if i[2] == 1]
print(len(a))
for i in a:
    print(i[0], i[1])

def main():
    q = int(input())
    users = []
    newusers = []
    for i in range(q):
        line = input().rstrip().split()
        old = line[0]
        new = line[1]
        if old not in newusers:
            users.append(old)
            newusers.append(new)
        else:
            index0 = newusers.index(old)
            newusers[index0] = new
    print(str(len(users)))
    for j in range(len(users)):
        print(users[j] + " " + newusers[j])
    
main()


def input_split(f): return list(map(f, input().split()))


def main():
    n = int(input())
    vals = []
    for i in range(n):
        vals.append(tuple(input_split(str)))

    res = {}
    for o, n in vals:
        if o in res:
            # aaa bbb, bbb, ccc -> aaa ccc
            # {bbb: aaa}
            res[n] = res[o]
            del res[o]
        else:
            res[n] = o
    print(len(res))
    for k in res:
        print("{} {}".format(res[k], k))


def __starting_point():
    main()

__starting_point()

dic = {}
s = int(input())
i=0
while (i < s):
    x = input()
    h = x.split()
    if h[0] in dic:
        dic[h[1]] = dic.pop(h[0])
    else:
        dic[h[1]] = h[0]
    i+=1
print(len(dic))
for x in dic:
    print(dic[x] + " " + x)


def main():
    n = int(input())
    Handels = []
    for i in range(n):
        rdl = input().split()
        if not rdl[0] in Handels:
            Handels.append(rdl[0])
            Handels.append(rdl[1])
        else: 
            ind = Handels.index(rdl[0])
            Handels[ind] = rdl[1]
    i = 0
    print(int(len(Handels)/2))
    while i < len(Handels):
        print(Handels[i], Handels[i+1])
        i +=2
main()

n = int(input())
d = {}
for i in range(n):
    a, b = input().split()
    bo = True
    for j in d:
        if a == d[j]:
            d[j] = b
            bo = False
    if bo:
        d[a] = b
print(len(d))
for i in d:
    print(i, d[i])


n =int(input())
d={}
for i in range(n):
   old,new= input().split()
   already=True
   for i in d:
      if old == d[i]:
         d[i]=new
         already=False
   if already:
      d[old]=new
print(len(d))
for i in d.keys():
   print(str(i)+" "+str(d[i]))

a = int(input(""))
#Alex Gu Is fat
inputs = []
for value in range(a):
    a = input("").split(" ")
    inputs.append(a)
#Alex Gu is still fat
handles = []
guFat = []
for value in inputs:
    string = value[0] + " " + value[1]
    if value[0] not in handles:
        handles.append(value[1])
        guFat.append(string)
    if value[0] in handles:
        handles.remove(value[0])
        handles.append(value[1])
        for k in guFat:
            impor = k.split(" ")
            if value[0] == impor[1]:
                guFat.remove(k)
                guFat.append(impor[0] + " " + value[1])
    
    #Guess what? Alex Gu is still fat!
print(len(handles))
for value in guFat:
    print(value)