Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.

The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim.

You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.


-----Input-----

First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 ≤ n ≤ 1000), the number of days.

Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person.

The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters.


-----Output-----

Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.


-----Examples-----
Input
ross rachel
4
ross joey
rachel phoebe
phoebe monica
monica chandler

Output
ross rachel
joey rachel
joey phoebe
joey monica
joey chandler

Input
icm codeforces
1
codeforces technex

Output
icm codeforces
icm technex



-----Note-----

In first example, the killer starts with ross and rachel.   After day 1, ross is killed and joey appears.  After day 2, rachel is killed and phoebe appears.  After day 3, phoebe is killed and monica appears.  After day 4, monica is killed and chandler appears.

Difficulty: competition

Starter code:

Solutions:
import sys

s1, s2 = input().split()
n = int(input())

for _ in range(n):
    print(s1, s2)
    killed, new = input().split()
    if s1 == killed:
        s1 = new
    else:
        s2 = new

print(s1, s2)


def main():
	a, b = map(str, input().split())
	n = int(input())
	print(a, b)
	for i in range(n):
		x, y = map(str, input().split())
		if (x == a):
			a = y
		else:
			b = y
		print(a, b)


main()

a,b=input().split()
print(a,b)
for i in range(int(input())):
    c,d=input().split()
    if a==c:
        a=d
    elif b==c:
        b=d
    print(a,b)


import collections as col
import itertools as its
import copy


def main():
    s = set()
    a, b = input().split(' ')
    s.add(a)
    s.add(b)
    n = int(input())
    for i in range(n):
        print(' '.join(list(s)))
        a, b = input().split()
        s.remove(a)
        s.add(b)
    print(' '.join(list(s)))


def __starting_point():
    main()

__starting_point()

3

names = input().split()
n = int(input())
for i in range(n):
    print(' '.join(names))
    sep = input().split()
    if names[0] == sep[0]:
        names[0] = sep[1]
    if names[1] == sep[0]:
        names[1] = sep[1]
    
print(' '.join(names))


n, m = input().split()
k = int(input())
print(n, m)
for i in range(k):
    nn, nm = input().split()
    if nn == n:
        n = nm
    else:
        m = nm
    print(n, m)


l = input().split()
print(*l)
n = int(input())
for i in range(n):
	t = input().split()
	i = 0
	if l[1] == t[0]:
		i = 1
	l[i] = t[1]
	print(*l)



3

s, t = input().split()
print(s, t)
n = int(input())
for i in range(n):
    w, y = input().split()
    if s == w:
        s = y
    else:
        t = y
    print(s, t)
    


a, b = input().split()
n = int(input())

couples = []

for i in range(n):
	couples.append(input().split())

for j in range(n):
	print(a, b)
	if couples[j][0] == a:
		a = couples[j][1]
	else:
		b = couples[j][1]

print(a, b)

X,Y = input().split()
print(X, Y)
for i in range(int(input())):
	A, B = input().split()
	if X==A: X = B
	elif Y==A: Y = B
	print(X,Y)



import sys

fin = sys.stdin
fout = sys.stdout
cur = fin.readline().split()
n = int(fin.readline())
fout.write(' '.join(cur) + '\n')
for i in range(n):
    curS = fin.readline().split()
    pos = cur.index(curS[0])
    cur[pos] = curS[1]
    fout.write(' '.join(cur) + '\n')

names = input().split()
n = int(input())
print(" ".join(names))
for i in range(n):
    died, new = input().split()
    
    if died == names[0]:
        names = [new, names[1]]
    else:
        names = [names[0], new]
        
    print(" ".join(names))

s1, s2 = input().split()

n = int(input())
for i in range(n):
    print(s1, s2)
    killed, new = input().split()
    if s1 == killed:
        s1 = new
    else:
        s2 = new
        
print(s1, s2)

victims = input().split()
print(" ".join(victims))
n = int(input())
for i in range(n):
    killed, replaced = input().split()
    if victims[0] == killed:
        victims[0] = replaced
    else:
        victims[1] = replaced
    print(" ".join(victims))


a, b=input().split()
print(a, b)

for _ in range(int(input())):
	c, d=input().split()
	if a==c:
		a=d
	else:
		b=d
	print(a, b)


from sys import stdin

name1, name2 = [x.strip() for x in input().split()]
n = int(input())
print(name1, name2)
d = {name1, name2}
for i in range(n):
    n1, n2 = [x.strip() for x in input().split()]
    d.discard(n1)
    d.add(n2)
    ans = ' '.join(d)
    print(ans)

a, b = input().strip().split()
n = int(input())
for i in range(n):
    print(a, b)
    c, d = input().strip().split()
    if a == c:
        a = d
    else:
        b = d
print(a, b)


name1, name2 = input().split()

n = int(input())

for i in range(n):
    print(name1, name2)
    killed, new = input().split()
    if killed == name1:
        name1 = new
    else:
        name2 = new

print(name1, name2)


a,b=input().split()
n=int(input())
print(a,b)
for i in range(n):
    c,d=input().split()
    if c==a:a=d
    else:b=d
    print(a,b)


s1, s2 = list(map(str, input().split()))
l = []
l += [s1, s2]
n = int(input())
for i in range(n):
    s3, s4 = list(map(str, input().split()))
    if s1 == s3:
        s1 = s4
    else:
        s2 = s4
    l += [s1, s2]
for i in range(2 * n + 2):
    if i % 2 == 0:
        print(l[i], l[i + 1])

a, b = input().split()
n = int(input())
print(a, b)
for i in range(n):
    c, d = input().split()
    if c == a:
        a = d
    else:
        b = d
    print(a, b)


n1, n2 = input().split()

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

sel = set([n1, n2])
for killed, next in names:
    print(" ".join(sel))
    sel.remove(killed)
    sel.add(next)
print(" ".join(sel))


a, b = input().split()
N = int(input())
print(a, b)
for n in range(N):
	c, d = input().split()
	if c == a:
		a = d
	elif c == b:
		b = d
	elif d == a:
		a = c
	elif d == b:
		b = c
	print(a, b)

ss = input().split()

N = int ( input() )


print( ss[0] , ss[1] )

for x in range(N):
	
	zz = input().split()
	if ( zz[0] == ss[0] ):
		ss[0] = zz[1]
	else :
		ss[1] = zz[1]
	print( ss[0] , ss[1] )
		



a=input().split()
n=int(input())
for i in range(n):
    print(a[0],a[1])
    s1,s2=input().split()
    a[a.index(s1)]=s2
print(a[0],a[1])