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.

Source: codeforces | Difficulty: EASY
Tags: String algorithms

Implementation

Complete search


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


s = input().split()
print(' '.join(s))
n = int(input())
for i in range(n):
	(n1, n2) = input().split()
	s[s.index(n1)] = n2
	print(' '.join(s))


(v1, v2) = [x for x in input().split(' ')]
n = int(input())
print(v1 + ' ' + v2)
for i in range(n):
	(murd, repl) = [x for x in input().split(' ')]
	if v1 == murd:
		v1 = repl
	else:
		v2 = repl
	print(v1 + ' ' + v2)


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


a = input().split()
x = int(input())
s = [input().split() for i in range(x)]
print(a[0], a[1])
t = a[0]
t1 = a[1]
for i in range(x):
	if s[i][0] == t:
		print(t1, s[i][1])
		t = t1
		t1 = s[i][1]
	elif s[i][0] == t1:
		print(t, s[i][1])
		t1 = s[i][1]


(l1, l2) = input().split()
number = int(input())
newOne = ''
newTwo = ''
print(l1, l2)
for i in range(number):
	(newOne, newTwo) = input().split()
	if l1 == newOne:
		l1 = newTwo
	elif l2 == newOne:
		l2 = newTwo
	print(l1, l2)


a = input().split()
print(*a)
c = int(input())
for i in range(c):
	(d, e) = input().split()
	a[a.index(d)] = e
	print(*a)


names = list(map(str, input().split()))
n = int(input())
print(*names)
for i in range(n):
	(s1, s2) = map(str, input().split())
	if names[0] == s1:
		names[0] = s2
	else:
		names[1] = s2
	print(*names)


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))


import sys

def debug(x, table):
	for (name, val) in table.items():
		if x is val:
			print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
			return None

def solve():
	(p1, p2) = input().split()
	n = int(input())
	print(p1, p2)
	for i in range(n):
		(s1, s2) = input().split()
		if s1 == p1:
			p1 = s2
		else:
			p2 = s2
		print(p1, p2)
solve()


a = set()
a |= set(input().split(' '))
n = int(input())
print(*a)
for _ in range(n):
	(s, t) = input().split(' ')
	a.remove(s)
	a.add(t)
	print(*a)


l = list(input().split())
print(*l)
for _ in range(int(input())):
	(m, n) = input().split()
	l[l.index(m)] = n
	print(*l)


s = list(input().split())
print(*s)
n = int(input())
for i in range(n):
	x = list(input().split())
	s[s.index(x[0])] = x[1]
	print(*s)


s = input()
n = int(input())
print(s)
s = s.split()
for _ in range(n):
	a = input().split()
	s.remove(a[0])
	s.append(a[1])
	print(*s)


a = input().split()
x = int(input())
print(' '.join(a))
for i in range(x):
	x = input().split()
	a[a.index(x[0])] = x[1]
	print(' '.join(a))


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


import sys
(a, b) = input().split()
print(a, b)
(x, y) = (a, b)
n = int(input())
for i in range(n):
	(a, b) = input().split()
	if a == x or a == y:
		if a == x:
			x = b
		else:
			y = b
	elif b == x:
		x = a
	else:
		y = b
	print(x, y)


(victim1, victim2) = input().split()
print(victim1, victim2)
for _ in range(int(input())):
	(killed, replacement) = input().split()
	if victim1 == killed:
		victim1 = replacement
	else:
		victim2 = replacement
	print(victim1, victim2)


(op1, op2) = [x for x in input().split(' ')]
print(op1, op2)
n = int(input())
while n:
	n -= 1
	(x, y) = [x for x in input().split(' ')]
	if x == op1:
		op1 = y
	elif x == op2:
		op2 = y
	print(op1, op2)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
(a, b) = input().split()
print(a, b)
n = I()
for i in range(n):
	k = input().split()
	if a == k[0]:
		a = k[1]
	else:
		b = k[1]
	print(a, b)


(x, y) = input().split()
n = int(input())
res = []
res.append((x, y))
for i in range(n):
	(a, b) = input().split()
	if a == x:
		x = b
	elif a == y:
		y = b
	res.append((x, y))
for (a, b) in res:
	print(a + ' ' + b)


ini = input().split()
print(ini[0], ini[1])
for i in range(int(input())):
	s = input().split()
	if s[0] == ini[0]:
		ini[0] = s[1]
	else:
		ini[1] = s[1]
	print(ini[0], ini[1])


def solve(a, b, c, d):
	if a == c:
		a = d
	else:
		b = d
	return (a, b)

def main():
	(a, b) = input().split()
	print(a, b)
	n = int(input())
	for _ in range(n):
		(c, d) = input().split()
		(a, b) = solve(a, b, c, d)
		print(a, b)
main()


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)))
main()


List = list(map(str, input().split()))
a = List[0]
b = List[1]
n = int(input())
kill = []
replace = []
for i in range(n):
	Killer = list(map(str, input().split()))
	c = Killer[0]
	d = Killer[1]
	kill.append(a)
	replace.append(b)
	if c == a:
		a = d
	else:
		b = d
for i in range(n):
	print(kill[i], replace[i])
print(a, b)


(a, b) = map(str, input().split())
n = int(input())
l = []
l.append(a + ' ' + b)
for i in range(n):
	(c, d) = map(str, input().split())
	if c == a:
		l.append(d + ' ' + b)
		a = d
	if c == b:
		l.append(a + ' ' + d)
		b = d
for i in l:
	print(i)


(victim_1, victim_2) = input().split()
n = int(input())
print('%s %s' % (victim_1, victim_2))
for i in range(n):
	(a, b) = input().split()
	if victim_1 == a:
		victim_1 = b
	else:
		victim_2 = b
	print('%s %s' % (victim_1, victim_2))


will = input().split()
n = int(input())
for i in range(n):
	print(will[-2], will[-1])
	(a, b) = input().split()
	will.remove(a)
	will.append(b)
print(will[-2], will[-1])


histroy = []
state = input().split(' ')
histroy.append(tuple(state))
for i in range(int(input())):
	next = input().split()
	for i in range(2):
		if next[0] == state[i]:
			state[i] = next[1]
	histroy.append(tuple(state))
for day in histroy:
	print(day[0] + ' ' + day[1])


s = input().split()
print(s[0], s[1])
t = int(input())
while t > 0:
	t -= 1
	s1 = input().split()
	if s[0] == s1[0]:
		s[0] = s1[1]
	else:
		s[1] = s1[1]
	print(s[0], s[1])


import re
sk = [input().split()]
n = int(input())
for x in range(n):
	n1 = input().split()
	if re.match(sk[x][0], n1[0]) and re.match(n1[0], sk[x][0]):
		sk.append([n1[1], sk[x][1]])
	else:
		sk.append([sk[x][0], n1[1]])
for x in range(n + 1):
	print(sk[x][0], sk[x][1])


(kill, replace) = list(input().strip().split(' '))
print(kill, replace)
n = int(input())
for i in range(n):
	(p1, p2) = list(input().strip().split(' '))
	if kill == p1:
		kill = replace
		replace = p2
	else:
		replace = kill
		kill = p2
	print(kill, replace)


init = input().split()
n = int(input())
lst = [init[:]]
for x in range(n):
	inp = input().split()
	init.remove(inp[0])
	init.append(inp[1])
	lst.append(init[:])
for x in lst:
	print(' '.join(x))


l = list(map(str, input().split()))
n = int(input())
for i in l:
	print(i, end=' ')
print('')
for i in range(n):
	ll = list(map(str, input().split()))
	if l[0] == ll[0]:
		l[0] = ll[1]
	else:
		l[1] = ll[1]
	for j in l:
		print(j, end=' ')
	print('')


s = set(input().split(' '))
n = int(input())
l = []

def ans():
	for num in s:
		l.append(num)
	print(' '.join(l))
	l.clear()
ans()
for i in range(n):
	(s1, s2) = map(str, input().split(' '))
	s.remove(s1)
	s.add(s2)
	ans()


(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))


s = list(map(str, input().split()))
print(*s)
for cas in range(int(input())):
	t = list(map(str, input().split()))
	if s[0] == t[0]:
		s[0] = t[1]
	elif s[0] == t[1]:
		s[0] = t[0]
	elif s[1] == t[0]:
		s[1] = t[1]
	else:
		s[1] = t[0]
	print(*s)


initial = input().split()
n = int(input())
victims = []
m = n
while m > 0:
	(s, t) = input().split()
	victims.append([s, t])
	m -= 1
answer = initial[0] + ' ' + initial[1]
for i in range(len(victims)):
	if initial[0] == victims[i][0]:
		initial[0] = victims[i][1]
		answer += '\n' + initial[0] + ' ' + initial[1]
	elif initial[1] == victims[i][0]:
		initial[1] = victims[i][1]
		answer += '\n' + initial[0] + ' ' + initial[1]
print(answer)


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


l = list(map(str, input().split()))
print(*l)
n = int(input())
for i in range(n):
	(a, b) = map(str, input().split())
	l.remove(a)
	l.append(b)
	print(*l)


(a, b) = input().split()
n = int(input())
print(a, b)
for i in range(n):
	(a1, a2) = input().split()
	if a == a1:
		a = a2
	elif b == a1:
		b = a2
	elif a == a2:
		a = a1
	elif b == a2:
		b = a1
	print(a, b)


(nome1, nome2) = input().split()
print(nome1, nome2)
for i in range(int(input())):
	(assassinado, substituto) = input().split()
	if assassinado == nome1:
		nome1 = substituto
	else:
		nome2 = substituto
	print(nome1, nome2)


names = set(input().split())
n = int(input())
for i in range(n):
	print(*names)
	(f, s) = input().split()
	if f in names:
		names.remove(f)
		names.add(s)
	else:
		names.remove(s)
		names.add(f)
print(*names)


import sys
from itertools import product
from functools import reduce
import math
(s1, s2) = input().strip().split(' ')
print('{} {}'.format(s1, s2))
N = int(input().strip())
for n in range(N):
	(killed, cand) = input().strip().split(' ')
	if s1 == killed:
		s1 = cand
	else:
		s2 = cand
	print('{} {}'.format(s1, s2))


read = lambda : map(int, input().split())
(a, b) = input().split()
n = int(input())
ans = [list() for i in range(n + 1)]
ans[0] = (a, b)
for i in range(1, n + 1):
	(a, b) = input().split()
	if ans[i - 1][0] == a:
		ans[i] = (ans[i - 1][1], b)
	else:
		ans[i] = (ans[i - 1][0], b)
for i in range(n + 1):
	print(*ans[i])


(name1, name2) = map(str, input().split())
n = int(input())
victims = []
next_victims = []
for i in range(n):
	(v_name, replaced_v) = map(str, input().split())
	victims.append([v_name, replaced_v])
print(name1, name2)
count_lines = 0
for x in victims:
	if x[0] == name1 and count_lines < n:
		x[0] = x[1]
		x[1] = name2
		print(x[0], x[1])
		count_lines += 1
	if x[0] == name2 and count_lines < n:
		x[0] = name1
		print(x[0], x[1])
		count_lines += 1
	for i in range(len(victims) - 1):
		if x[1] == victims[i + 1][0] and count_lines < n:
			victims[i + 1][0] = x[0]
			x[1] = victims[i + 1][1]
			next_victims.append([victims[i + 1][0], x[1]])
			if x[0] == x[1]:
				break
			print(victims[i + 1][0], x[1])
			count_lines += 1
		elif x[0] == victims[i + 1][0] and count_lines < n:
			x[0] = victims[i + 1][1]
			next_victims.append([x[0], x[1]])
			if x[0] == x[1]:
				break
			print(x[0], x[1])
			count_lines += 1


(p1, p2) = list(map(str, input().split()))
li = []
li.append(p1 + ' ' + p2)
n = list(map(int, input().split()))[0]
for i in range(n):
	(p3, p4) = list(map(str, input().split()))
	if p3 == p1:
		li.append(p2 + ' ' + p4)
		p1 = p4
	elif p3 == p2:
		li.append(p1 + ' ' + p4)
		p2 = p4
for i in li:
	print(i)


(n, m) = map(str, input().split())
rang = []
rang.append([n, m])
days = int(input())
for i in range(days):
	(r, g) = map(str, input().split())
	if n == r:
		n = g
	else:
		m = g
	rang.append([n, m])
for i in range(days + 1):
	print(' '.join(map(str, rang[i])))


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


a = input().split()
n = int(input())
print(' '.join(a))
for i in range(n):
	(x, y) = input().split()
	a[a.index(x)] = y
	print(' '.join(a))


s = input().split()
n = int(input())
killed = [0] * n
for i in range(n):
	killed[i] = input().split()
print(s[0], s[1])
for i in range(n):
	if killed[i][0] == s[0]:
		s[0] = killed[i][1]
	else:
		s[1] = killed[i][1]
	print(s[0], s[1])


a = []
b = []
text = input()
a.append(text.split()[0])
b.append(text.split()[1])
n = int(input())
for i in range(n):
	text = input()
	a.append(text.split()[0])
	b.append(text.split()[1])
for i in range(n + 1):
	print(a[i], '', b[i])
	if i == n:
		continue
	if a[i] == a[i + 1]:
		a[i + 1] = b[i + 1]
		b[i + 1] = b[i]
	if b[i] == a[i + 1]:
		a[i + 1] = a[i]


dict = {}
for i in input().split():
	dict[i] = 1
for i in dict.keys():
	print(i, end=' ')
print()
n = int(input())
for i in range(n):
	(x, y) = input().split()
	del dict[x]
	dict[y] = 1
	for i in dict.keys():
		print(i, end=' ')
	print()


(n, m) = input().split()
k = int(input())
l = []
l.append([n, m])
for _ in range(k):
	(a, b) = input().split()
	if a == n:
		n = b
	elif a == m:
		m = b
	l.append([n, m])
for i in l:
	print(*i)


y = list(map(str, input().split()))
for _ in range(0, int(input())):
	x = input().split()
	y.extend(x)
print(y[0], y[1], end=' ')
print()
for i in range(2, len(y), 2):
	if y[i] == y[i - 2]:
		y[i] = y[i - 1]
	elif y[i] == y[i - 1]:
		y[i] = y[i - 2]
for i in range(2, len(y), 2):
	print(y[i], y[i + 1])


ls = input().split()
for i in range(int(input())):
	v = input().split()
	print(*ls)
	ls.remove(v[0])
	ls.append(v[1])
print(*ls)


m = set([i for i in input().split()])
n = int(input())
l = [set([i for i in input().split()]) for i in range(n)]
print(*m)
for i in l:
	m ^= i
	print(*m)


v = input().split(' ')
print(*v)
n = int(input())
for i in range(n):
	w = input().split(' ')
	v.remove(w[0])
	v.append(w[1])
	print(*v)


(n1, n2) = input().split()
print(n1, n2)
s = set([n1, n2])
n = int(input())
for i in range(n):
	(n1, n2) = input().split()
	s -= set([n1])
	s.add(n2)
	print(*s)


(first, second) = input().split()
n = int(input())
print(first, second)
for i in range(n):
	(corp, alive) = input().split()
	if corp == first:
		first = alive
	else:
		second = alive
	print(first, second)


(name1, name2) = input().split()
n = int(input())
print(name1, name2)
while n > 0:
	(p, q) = input().split()
	if p == name1:
		name1 = q
		print(name1, name2)
		n = n - 1
		continue
	if p == name2:
		name2 = q
		print(name1, name2)
		n = n - 1
		continue
	if q == name1:
		name1 = p
		print(name1, name2)
		n = n - 1
		continue
	if q == name2:
		name2 = p
		print(name1, name2)
		n = n - 1
		continue


names = input().split()
n = int(input())
ans = list()
ans.append(names.copy())
for i in range(n):
	(old, new) = input().split()
	names[names.index(old)] = new
	ans.append(names.copy())
print('\n'.join([' '.join(i) for i in ans]))


R = lambda : [x for x in input().split()]
(one, two) = R()
print(one, two)
n = int(input())
for _ in range(n):
	(aone, atwo) = R()
	if one == aone:
		one = atwo
	if two == aone:
		two = atwo
	print(one, two)


people = input().split()
n = int(input())
print(' '.join(people))
for i in range(n):
	(p1, p2) = input().split()
	people[people.index(p1)] = p2
	print(' '.join(people))


s = input().split()
n = int(input())
while n:
	v = input().split()
	for i in s:
		print(i, end=' ')
	print()
	s = [v[1] if x == v[0] else x for x in s]
	n -= 1
for i in s:
	print(i, end=' ')
print()


(n, m) = map(str, input().split())
(s, k) = (n, m)
print(s, k)
for i in range(int(input())):
	(q, w) = map(str, input().split())
	if s == q:
		s = w
		print(s, k)
	else:
		k = w
		print(s, k)


s = input().strip().split(' ')
n = int(input())
print(s[0], s[1])
for _ in range(n):
	f = input().strip().split(' ')
	if f[0] == s[0]:
		s[0] = f[1]
	elif f[0] == s[1]:
		s[1] = f[1]
	elif f[1] == s[0]:
		s[0] = f[0]
	else:
		s[1] = f[0]
	print(s[0], s[1])


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 = input().split()
n = int(input())
print(*a)
for i in range(n):
	b = input().split()
	a[a.index(b[0])] = b[1]
	print(*a)


s = str(input())
ans = s + '\n'
for i in range(int(input())):
	x = str(input())
	y = x.split()[0]
	if s.split()[0] == y:
		ans = ans + x.split()[1] + ' '
		ans = ans + s.split()[1] + '\n'
		s = x.split()[1] + ' ' + s.split()[1]
	else:
		ans = ans + x.split()[1] + ' '
		ans = ans + s.split()[0] + '\n'
		s = x.split()[1] + ' ' + s.split()[0]
print(ans.strip())


(a, b) = input().split()
n = int(input())
arr = []
for i in range(n):
	t = input().split()
	arr.append(t)
print(a, b)
for i in range(n):
	if arr[i][0] == a:
		a = arr[i][1]
	else:
		b = arr[i][1]
	print(a, b)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))
s = get_char_list()
for i in range(get_int()):
	print(' '.join(s))
	t = get_char_list()
	s[s.index(t[0])] = t[1]
print(' '.join(s))


import math, sys

def main():
	(first, second) = input().split()
	n = int(input())
	for i in range(n):
		print(first, second)
		(kill, zher) = input().split()
		if first == kill:
			first = zher
		if second == kill:
			second = zher
	print(first, second)
main()


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	(a, b) = LS()
	n = I()
	aa = [LS() for _ in range(n)]
	rr = [[a, b]]
	for (c, d) in aa:
		if c == a:
			a = d
		else:
			b = d
		rr.append([a, b])
	return '\n'.join(map(lambda x: ' '.join(x), rr))
print(main())


(s1, s2) = input().split()
n = int(input())
print(s1, s2)
while n > 0:
	n -= 1
	(a, b) = input().split()
	if a == s1:
		s1 = b
	else:
		s2 = b
	print(s1, s2)


(f, s) = input().split()
print(f, s)
n = int(input())
for i in range(n):
	(a, b) = input().split()
	if a == f:
		f = b
	elif a == s:
		s = b
	print(f, s)


from sys import *
st = set(input().split())
n = int(input())
for j in st:
	stdout.write(j + ' ')
stdout.write('\n')
for i in range(n):
	p = input().split()
	st.discard(p[0])
	st.add(p[1])
	for j in st:
		stdout.write(j + ' ')
	stdout.write('\n')


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()


arr = input().split()
n = int(input())
for i in range(n):
	print(*arr)
	(x, y) = input().split()
	if arr[0] == x:
		arr[0] = y
	else:
		arr[1] = y
print(*arr)


def main():
	l = input().split()
	print(*l)
	for _ in range(int(input())):
		(a, b) = input().split()
		l[a == l[1]] = b
		print(*l)
main()


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


victims = list(map(str, input().strip().split(' ')))
n = int(input())
print(victims[0], victims[1])
for i in range(n):
	aux = list(map(str, input().strip().split(' ')))
	if aux[0] == victims[0]:
		victims[0] = aux[1]
	elif aux[0] == victims[1]:
		victims[1] = aux[1]
	print(victims[0], victims[1])


(a, b) = input().split()
n = int(input())
l = []
h = []
h.append([a, b])
for i in range(n):
	l.append(input().split())
for i in range(n):
	if h[i][0] == l[i][0]:
		h.append([l[i][1], h[i][1]])
	elif h[i][1] == l[i][0]:
		h.append([h[i][0], l[i][1]])
for i in range(len(h)):
	for j in range(2):
		print(h[i][j], end=' ')
	print()


arr = input().split()
n = int(input())
ans1 = arr[0]
ans2 = arr[1]
print(ans1, ans2)
for i in range(0, n):
	name = input().split()
	if arr[0] == name[0]:
		arr[0] = name[1]
	else:
		arr[1] = name[1]
	ans1 = arr[0]
	ans2 = arr[1]
	print(ans1, ans2)


(n1, n2) = map(str, input().split())
n = int(input())
for i in range(n):
	(v, f) = map(str, input().split())
	print(n1, n2)
	if v == n1:
		n1 = f
	else:
		n2 = f
print(n1, n2)


(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)


(a, b) = input().split()
n = int(input())
for i in range(n):
	(p, q) = input().split()
	print(a, b)
	if p == a:
		a = q
	elif b == p:
		b = q
	if i == n - 1:
		print(a, b)


(m, n) = map(str, input().split())
(m, n) = (m.lower(), n.lower())

def serial_killer(x, y):
	global m, n
	if x == m:
		m = y
		print(str(m) + ' ' + str(n))
	if x == n:
		n = y
		print(str(m) + ' ' + str(n))
p = int(input())
print(str(m) + ' ' + str(n))
for _ in range(p):
	(x, y) = map(str, input().split())
	(x, y) = (x.lower(), y.lower())
	serial_killer(x, y)


k = input().split()
l = int(input().split()[0])
pp = [k[0], k[1]]
for i in range(0, l):
	p = input().split()
	if pp[-2] == p[0]:
		pp.append(p[1])
		pp.append(pp[-2])
	else:
		pp.append(pp[-2])
		pp.append(p[1])
for j in range(0, 2 * l + 1, 2):
	print(pp[j] + ' ' + pp[j + 1])


s = list(map(str, input().split()))
n = int(input())
print(*s)
for i in range(n):
	(dell, neww) = map(str, input().split())
	s[s.index(dell)] = neww
	print(*s)


import sys

def main():
	candidates = set(sys.stdin.readline().split())
	num = int(sys.stdin.readline().rstrip())
	for __ in range(num):
		(killed, repl) = sys.stdin.readline().split()
		candidates.remove(killed)
		print(killed, list(candidates)[0])
		candidates.add(repl)
	print(' '.join(candidates))
main()


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])


(f1, f2) = list(map(str, input().split()))
print(f1, f2)
n = int(input())
for _ in range(n):
	(dead, replace) = list(map(str, input().split()))
	if dead == f1:
		f1 = replace
	else:
		f2 = replace
	print(f1, f2)


init_victims = list(map(str, input().split()))
next_victims = []
current_victims = init_victims
t = int(input())
for x in range(t):
	next_victims += list(map(str, input().split()))
print(' '.join(init_victims))
while t != 0:
	current_victims.remove(next_victims.pop(0))
	current_victims.append(next_victims.pop(0))
	print(' '.join(current_victims))
	t -= 1


import sys
if False:
	practice = open('tsample_input.txt', 'r')
else:
	practice = sys.stdin
a = practice.read().splitlines()
b = []
for line in a:
	c = line.split(' ')
	b.append(c)
first = b[0][0]
second = b[0][1]
print(first, second)
for j in range(len(b) - 2):
	for i in range(1):
		if b[j + 2][i] == first:
			first = b[j + 2][i + 1]
		else:
			second = b[j + 2][i + 1]
		print(first, second)


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


(v1, v2) = map(str, input().split())
days = int(input())
victims = [[v1, v2]]
while days > 0:
	(killed, new) = map(str, input().split())
	if killed == v1:
		v1 = new
	else:
		v2 = new
	victims.append([v1, v2])
	days -= 1
for i in victims:
	print(' '.join(i))


A = input().split()
n = int(input())
print(A[0], ' ', A[1])
for i in range(n):
	B = input().split()
	if A[0] == B[0]:
		A[0] = B[1]
	else:
		A[1] = B[1]
	print(A[0], ' ', A[1])


(name1, name2) = input().split()
i = int(input())
c = 0
while c < i and 0 <= i <= 1000:
	print(name1, name2)
	(name3, name4) = input().split()
	if name1 == name3 or name1 == name4:
		name1 = name4
	if name2 == name4 or name2 == name3:
		name2 = name4
	c += 1
	if c >= i:
		print(name1, name2)


__author__ = 'Ryabchun Vladimir'
ans = []
fd = list(map(str, input().split()))
ans.append(fd)
n = int(input())
for i in range(1, n + 1):
	(name1, name2) = map(str, input().split())
	aimin1 = list(ans[i - 1])
	aimin1.remove(name1)
	ans.append([*aimin1, name2])
for line in ans:
	print(*line)


def replace(input, inputs):
	afind = inputs.find(' ')
	a = inputs[0:afind]
	inputs = inputs[afind + 1:]
	b = inputs[0:]
	afind = input.find(' ')
	a1 = input[0:afind]
	input = input[afind + 1:]
	b1 = input[0:]
	if a1 == a:
		a1 = b
	else:
		b1 = b
	return a1 + ' ' + b1
array = []
array.append(input(''))
num = int(input(''))
for x in range(0, num):
	stuff = input('')
	array.append(stuff)
print(array[0])
for x in range(0, len(array)):
	if x + 1 != len(array):
		array[x + 1] = replace(array[x], array[x + 1])
		print(array[x + 1])


s = input().split()
lis = []
lis.append(' '.join(s))
n = int(input())
for i in range(n):
	(m, n) = input().split()
	s[s.index(m)] = n
	lis.append(' '.join(s))
for i in lis:
	print(i)


line = list(map(str, input().split()))
print(' '.join(line))
n = int(input())
for i in range(n):
	(a, b) = map(str, input().split())
	if a == line[0]:
		line[0] = b
	elif a == line[1]:
		line[1] = b
	print(' '.join(line))


name = []
name.append(input().split())
n = int(input())
for i in range(n):
	(p1, p2) = input().split()
	if name[i][0] == p1:
		name.append([p2, name[i][1]])
	else:
		name.append([name[i][0], p2])
for n in name:
	print(n[0], n[1])


def main():
	(first, second) = map(str, input().split())
	print(first, second)
	n = int(input())
	while n > 0:
		n -= 1
		(killed, replaced) = map(str, input().split())
		if killed == first:
			first = replaced
		else:
			second = replaced
		print(first, second)
main()


(c, d) = input().split()
n = int(input())
z = []
print(c, d)
for i in range(n):
	(a, b) = input().split()
	x = ''
	if c == a:
		x = b
		c = x
		print(x, d)
	elif d == a:
		x = b
		d = x
		print(c, x)


S = set(input().split())
for x in S:
	print(x, end=' ')
print()
for i in range(int(input())):
	(a, b) = input().split()
	S.remove(a)
	S.add(b)
	for x in S:
		print(x, end=' ')
	print()


from math import *
from collections import deque
from copy import deepcopy
import sys

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def multi():
	return map(int, input().split())

def strmulti():
	return map(str, inp().split())

def lis():
	return list(map(int, inp().split()))

def lcm(a, b):
	return a * b // gcd(a, b)

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def stringlis():
	return list(map(str, inp().split()))

def out(var):
	sys.stdout.write(str(var))

def printlist(a):
	print(' '.join((str(a[i]) for i in range(len(a)))))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True
a = stringlis()
n = int(input())
print(a[0], a[1])
for i in range(n):
	temp = stringlis()
	if temp[0] == a[0]:
		a[0] = temp[1]
	else:
		a[1] = temp[1]
	print(a[0], a[1])


s_p = set(input().split())
print(' '.join(s_p))
for _ in range(int(input())):
	(s1, s2) = input().split()
	s_p.remove(s1)
	s_p.add(s2)
	print(' '.join(s_p))


s = input().split()
d = {s[0]: s[0], s[1]: s[1]}
print(' '.join(d.keys()))
for _ in range(int(input())):
	s = input().split()
	if s[0] in d:
		del d[s[0]]
	else:
		d[s[0]] = s[0]
	if s[1] in d:
		del d[s[1]]
	else:
		d[s[1]] = s[1]
	print(' '.join(d.keys()))


first_day = list(map(str, input().split(' ')))
days = int(input())
print('%s %s' % (first_day[0], first_day[1]))
for x in range(days):
	new_names = list(map(str, input().split(' ')))
	first_day[first_day.index(new_names[0])] = new_names[1]
	print('%s %s' % (first_day[0], first_day[1]))


lst = input().split(' ')
n = int(input())
last = lst[:]
for i in range(n):
	lst.append(None)
	lst.append(None)
	f = input().split(' ')
	if f[0] == last[0]:
		lst[-2] = f[1]
		lst[-1] = lst[-3]
	else:
		lst[-1] = f[1]
		lst[-2] = lst[-4]
	last = lst[-2:]
for k in range(0, len(lst), 2):
	print(lst[k] + ' ' + lst[k + 1])


try:

	def solve():
		s = input().split()
		n = int(input())
		print(s[0], s[1])
		for i in range(n):
			y = input().split()
			s[s.index(y[0])] = y[1]
			print(s[0], s[1])
	t = 1
	for _ in range(t):
		solve()
except:
	pass


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


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)


list_1 = list(input().split())
day = input()
print(*list_1, sep=' ')
for i in range(int(day)):
	(dead, alive) = input().split()
	if dead in list_1:
		list_1.remove(dead)
		list_1.append(alive)
	print(*list_1, sep=' ')


(str1, str2) = map(str, input().split())
n = int(input())
print(str1, str2)
for each in range(n):
	(murdered, replace) = map(str, input().split())
	if str1 == murdered:
		str1 = replace
		print(str1, str2)
	else:
		str2 = replace
		print(str1, str2)


import itertools

def main():
	(a, b) = [v.strip() for v in input().split()]
	names = {a, b}
	n = int(input())
	print(' '.join(list(names)))
	for i in range(n):
		(na, nb) = [v.strip() for v in input().split()]
		names.remove(na)
		names.add(nb)
		print(' '.join(list(names)))
main()


s = input().split()
print(*s)
for i in range(int(input())):
	(x, y) = input().split()
	s[s.index(x)] = y
	print(*s)


def main():
	(n1, n2) = input().split()
	print(n1, n2)
	names = {n1, n2}
	k = int(input())
	for i in range(k):
		(killed, new) = input().split()
		names.remove(killed)
		names.add(new)
		for name in names:
			print(name, end=' ')
		print()
main()


a = [i for i in input().split()]
n = int(input())
for x in range(n):
	print(a[0], a[1])
	b = [j for j in input().split()]
	if b[0] == a[0]:
		a[0] = b[1]
	else:
		a[1] = b[1]
print(a[0], a[1])


(s, p) = input().split()
n = int(input())
print(s, p, sep=' ', end='\n')
for i in range(n):
	(s1, s2) = input().split()
	(p, s) = (s if s1 == p else p, s2)
	print(s, p, sep=' ', end='\n')


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


(p1, p2) = input().split()
n = int(input())
print(p1, p2)
for i in range(n):
	(killed, potential) = input().split()
	if killed == p1:
		print(p2, potential)
		p1 = potential
	elif killed == p2:
		print(p1, potential)
		p2 = potential


ls = list(map(str, input().split()))
n = int(input())
print(*ls)
for _ in range(n):
	tmp = list(map(str, input().split()))
	ls.remove(tmp[0])
	ls.append(tmp[1])
	print(*ls)


(victim1, victim2) = input().split()
print(victim1, victim2)
for _ in range(int(input())):
	(mudered, next) = input().split()
	if mudered == victim1:
		victim1 = next
	else:
		victim2 = next
	print(victim1, victim2)


def f(n1, n2, n3, n4):
	if n3 == n1:
		return (n4, n2)
	else:
		return (n1, n4)
(n1, n2) = input().split(' ')
n = int(input())
l = [[n1, n2]]
for i in range(n):
	(n1, n2) = input().split(' ')
	(n1, n2) = f(l[i][0], l[i][1], n1, n2)
	l.append([n1, n2])
for i in range(n + 1):
	print(l[i][0], l[i][1])


import sys
f = sys.stdin.read().split()
names = f[:2]
n = int(f[2])
print('{} {}'.format(f[0], f[1]))
for i in range(n):
	(killed, new) = f[3 + i * 2:3 + (i + 1) * 2]
	names[names.index(killed)] = new
	print('{} {}'.format(*names))


(a, b) = [i for i in input().split()]
n = int(input())
r = [[a, b]]
for j in range(n):
	(c, d) = [z for z in input().split()]
	if c == a:
		a = d
	else:
		b = d
	r.append([a, b])
for elem in r:
	print(*elem)


p = list(input().split(' '))
n = int(input().strip())
final = []
for i in range(n):
	p1 = list(input().split())
	final.append(p1)
print(p[0], p[1])
for i in final:
	p.remove(i[0])
	p.append(i[1])
	print(p[0], p[1])


l1 = input().split()
n = int(input())
for i in range(n):
	for name in l1:
		print(name, ' ', end='')
	l2 = input().split()
	if l2[0] == l1[0]:
		l1[0] = l2[1]
	else:
		l1[1] = l2[1]
	print()
for name in l1:
	print(name, ' ', end='')
print()


def solution():
	candidates = set(input().split())
	days = int(input())
	print(*candidates)
	for day in range(days):
		candidates ^= set(input().split())
		print(*candidates)

def main():
	solution()
main()


def solve():
	options = input().strip().split()
	n = int(input())
	print(options[0], options[1])
	for i in range(n):
		(victim, newguy) = input().strip().split()
		options.remove(victim)
		options.append(newguy)
		print(options[0], options[1])

def main():
	solve()
main()


a = input().split()
for _ in range(int(input())):
	print(*a)
	(c, d) = input().split()
	a.remove(c)
	a.append(d)
print(*a)


p = input().split()
n = int(input())
print(' '.join(p))
for i in range(n):
	(a, b) = input().split()
	p[p.index(a)] = b
	print(' '.join(p))


(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)


def solve():
	new_names = next(name_gen)
	solution = (names | new_names) - (new_names & names)
	print_names(solution)
	return solution

def read_names():
	while True:
		yield set(input().split())

def print_names(names):
	print(' '.join(names))

def main():
	global name_gen, names, n
	name_gen = read_names()
	names = next(name_gen)
	print_names(names)
	n = int(input())
	for _ in range(n):
		names = solve()
main()


(first, second) = input().split()
initial = [first, second]
n = int(input())
i = 0
victims = []
while i < n:
	(first, last) = input().split()
	victims.append([first, last])
	i += 1
i = 1
print(initial[0], initial[1])
if victims[0][0] == initial[0]:
	victims[0][0] = victims[0][1]
	victims[0][1] = initial[1]
elif victims[0][0] == initial[1]:
	victims[0][0] = initial[0]
print(victims[0][0], victims[0][1])
while i < n:
	if victims[i][0] == victims[i - 1][0]:
		victims[i][0] = victims[i][1]
		victims[i][1] = victims[i - 1][1]
	elif victims[i][0] == victims[i - 1][1]:
		victims[i][0] = victims[i - 1][0]
	print(victims[i][0], victims[i][1])
	i += 1


(p1, p2) = map(str, input().split(' '))
n = int(input())
print(p1, p2)
while n:
	(v1, v2) = map(str, input().split(' '))
	if v1 == p1:
		p1 = v2
		print(p1, p2)
	if v1 == p2:
		p2 = v2
		print(p1, p2)
	n -= 1


a = input().split()
print(*a)
c = int(input())
for x in range(c):
	(g, h) = input().split()
	a[a.index(g)] = h
	print(*a)


def main():
	(s1, s2) = input().split()
	n = int(input())
	print(s1, s2)
	while n > 0:
		(k1, k2) = input().split()
		if k1 == s1:
			s1 = k2
		else:
			s2 = k2
		n -= 1
		print(s1, s2)
main()


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


(n1, n2) = input().split()
n = int(input())
listkilled = []
listadded = []
answer = [n1 + ' ' + n2]
for i in range(n):
	tmp = input().split()
	listkilled.append(tmp[0])
	listadded.append(tmp[1])
for i in range(n):
	k = answer[i].split()
	if k[0] == listkilled[i]:
		answer.append(listadded[i] + ' ' + k[1])
	else:
		answer.append(listadded[i] + ' ' + k[0])
for i in range(n + 1):
	print(answer[i])


(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)


pair = set(input().split())
n = int(input())
for name in pair:
	print(name, end=' ')
print('')
for i in range(n):
	(a, b) = map(str, input().split())
	pair.remove(a)
	pair.add(b)
	for name in pair:
		print(name, end=' ')
	print('')


def main():
	state = dict.fromkeys(input().split())
	print(' '.join(list(state.keys())))
	for _ in range(int(input())):
		next_choices = input().split()
		del state[next_choices[0]]
		state[next_choices[1]] = 0
		print(' '.join(list(state.keys())))
main()


(a, b) = input().split(' ')
print(a, b)
n = int(input())
for i in range(n):
	(x1, x2) = input().split(' ')
	if a == x1:
		a = x2
	else:
		b = x2
	print(a, b)


l = input().split()
print(*l)
n = int(input())
for i in range(n):
	(m, n) = input().split()
	l[l.index(m)] = n
	print(*l)


(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)


(person1, person2) = map(str, input().split())
Amt_days = int(input())
Potential = []
Potential.append(person1)
Potential.append(person2)
Alive = ''
print(*Potential)
for i in range(Amt_days):
	(person1, person2) = map(str, input().split())
	for i in range(2):
		if Potential[i] == person1:
			Potential[i] = person2
			break
	print(*Potential)


(v1, v2) = map(str, input().split())
t = int(input())
print(v1, v2)
for i in range(t):
	(k, r) = map(str, input().split())
	if k == v1:
		v1 = r
		print(v1, v2)
	else:
		v2 = r
		print(v1, v2)


n = list(input().split())
print(n[0] + ' ' + n[1])
c = int(input())
for _ in range(c):
	k = list(input().split())
	if k[0] == n[0]:
		print(k[1] + ' ' + n[1])
		n[0] = k[1]
	if k[0] == n[1]:
		print(n[0] + ' ' + k[1])
		n[1] = k[1]


initial = input().split()
n = int(input())
victims = []
m = n
while m > 0:
	(_from, _to) = input().split()
	victims.append([_from, _to])
	m -= 1
answer = initial[0] + ' ' + initial[1]
for i in range(len(victims)):
	if initial[0] == victims[i][0]:
		initial[0] = victims[i][1]
		answer += '\n' + initial[0] + ' ' + initial[1]
	elif initial[1] == victims[i][0]:
		initial[1] = victims[i][1]
		answer += '\n' + initial[0] + ' ' + initial[1]
print(answer)


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


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


ans = [list(input().split())]
n = int(input())
for _ in range(n):
	(x, y) = input().split()
	(xo, yo) = (ans[-1][0], ans[-1][1])
	if xo == x:
		ans += [[y, yo]]
	else:
		ans += [[xo, y]]
for i in range(n + 1):
	ans[i] = ' '.join(ans[i])
print('\n'.join(ans))


(n, m) = input().split()
t = int(input())
print(n, m)
for i in range(t):
	(p, q) = input().split()
	if n == p:
		print(m, q)
		n = q
	else:
		print(n, q)
		m = q


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


a = [s for s in input().split()]
n = int(input())
for i in range(n):
	print(' '.join((j for j in a)))
	(x, y) = [s for s in input().split()]
	if a[0] == x:
		a[0] = y
	else:
		a[1] = y
print(' '.join((j for j in a)))


(l, r) = input().split()
n = int(input())
print(l, r)
for i in range(n):
	(m, nxt) = input().split()
	if m == l:
		l = nxt
	elif m == r:
		r = nxt
	print(l, r)


namez = input().split()
n = int(input())
for i in range(n):
	print(' '.join(namez))
	(name1, name2) = input().split()
	namez[namez.index(name1)] = name2
print(' '.join(namez))


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


s = list(input().split())
print(*s)
cases = int(input())
while cases:
	cases -= 1
	names = list(input().split())
	ind = s.index(names[0])
	s[ind] = names[1]
	print(*s)


l = input().split()
print(*l)
n = int(input())
for i in range(n):
	(a, b) = input().split()
	l.remove(a)
	l.append(b)
	print(*l)


initial = input().split(' ')
print(initial[0] + ' ' + initial[1])
numCases = int(input())
for _ in range(numCases):
	names = input().split(' ')
	if initial[0] == names[0]:
		initial[0] = names[1]
	else:
		initial[1] = names[1]
	print(initial[0] + ' ' + initial[1])


(v1, v2) = input().split(' ')
print(v1, v2)
n = int(input())
for i in range(n):
	(dead, new) = input().split(' ')
	if dead == v1:
		v1 = new
	else:
		v2 = new
	print(v1, v2)


a = list(map(str, input().split()))
n = int(input())
print(*a)
for i in range(n):
	(died, replaced) = map(str, input().split())
	if a[0] == died:
		a[0] = replaced
	else:
		a[1] = replaced
	print(*a)


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])


(f, k) = map(str, input().split())
n = int(input())
print(f, k)
t1 = f
t2 = k
for i in range(n):
	(v1, v2) = map(str, input().split())
	if v1 == t1:
		print(v2, t2)
		t1 = v2
		t2 = t2
	else:
		print(t1, v2)
		t1 = t1
		t2 = v2


line = input()
print(line)
now = line.split()
n = int(input())
for i in range(n):
	inp = input().strip()
	line = inp.split()
	for i in range(len(now)):
		if now[i] == line[0]:
			now[i] = line[1]
	for x in now:
		print(x, end=' ')
	print()


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


e = input().split()
print(*e)
n = int(input())
for x in range(n):
	x = input().split()
	e[e.index(x[0])] = x[1]
	print(*e)


a = list(map(str, input().split()))
n = int(input())
print(*a)
for i in range(n):
	(s, r) = map(str, input().split())
	a.remove(s)
	a.append(r)
	print(*a)


line = [x for x in input().split()]
(f1, f2) = (line[0], line[1])
n = int(input())
for i in range(n):
	print(f1, f2)
	line = [x for x in input().split()]
	(f3, f4) = (line[0], line[1])
	if f1 == f3:
		f1 = f4
	else:
		f2 = f4
print(f1, f2)


v = list(map(str, input().split()))
n = int(input())
print(*v)
for i in range(n):
	(v1, v2) = map(str, input().split())
	if v1 in v:
		v.remove(v1)
		v.append(v2)
		print(*v)


a = input()
a = a.split(' ')
x = []
x += a
j = int(input())
for i in range(j):
	a1 = input()
	a1 = a1.split(' ')
	if a[0] == a1[0]:
		a[0] = a1[1]
	elif a[0] == a1[1]:
		a[0] = a1[0]
	elif a[1] == a1[0]:
		a[1] = a1[1]
	elif a[1] == a1[1]:
		a[1] = a1[0]
	x += a
for k in range(0, 2 * j + 1, 2):
	print(x[k], x[k + 1])


(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])


(potential_victim_1, potential_victim_2) = input().split()
print(potential_victim_1, potential_victim_2)
n = int(input())
for i in range(n):
	(victim, next_potential_victim) = input().split()
	if potential_victim_1 == victim:
		print(potential_victim_2, next_potential_victim)
		potential_victim_1 = next_potential_victim
	else:
		print(potential_victim_1, next_potential_victim)
		potential_victim_2 = next_potential_victim


(oria, orib) = input().split()
print(oria, orib)
n = input()
for i in range(int(n)):
	(kill, newm) = input().split()
	if kill == oria:
		oria = newm
	else:
		orib = newm
	print(oria, orib)


(a, b) = input().split()
n = int(input())
print(a, b)
for _ in range(n):
	(old, new) = input().split()
	if old == a:
		a = new
	else:
		b = new
	print(a, b)


(a, b) = input().split()
n = int(input())
print(a, b)
s = [a, b]
for i in range(n):
	(x, y) = input().split()
	s.remove(x)
	s.append(y)
	print(*s)


from operator import itemgetter
name = input().split()
n = int(input())
print(name[0], name[1])
for i in range(n):
	names = input().split()
	if name[0] == names[0]:
		name[0] = names[1]
	else:
		name[1] = names[1]
	print(name[0], name[1])


n = list(input().split(' '))
num = int(input())
first = f'{n[0]} {n[1]}'
anslist = [first]
for _ in range(num):
	newstring = list(input().split(' '))
	if newstring[0] in n:
		if newstring[0] == n[0]:
			n[0] = newstring[1]
		else:
			n[1] = newstring[1]
	anslist.append(f'{n[0]} {n[1]}')
for i in anslist:
	print(i)


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


(a, b) = map(str, input().split())
print(a, b)
n = int(input())
for i in range(n):
	(h, k) = map(str, input().split())
	if h == a:
		a = k
	else:
		b = k
	print(a, b)


def main():
	a = input().split()
	print(*a)
	for i in range(int(input())):
		(b, c) = input().split()
		a[a.index(b)] = c
		print(*a)
main()


(n, m) = input().split()
day = int(input())
ans = [n + ' ' + m]
(last_1, last_2) = (n, m)
for _ in range(1, day + 1):
	(dead, replace) = input().split()
	if dead == last_1:
		ans.append(replace + ' ' + last_2)
		last_1 = replace
	else:
		ans.append(last_1 + ' ' + replace)
		last_2 = replace
for i in ans:
	print(i)


(a, b) = input().split()
n = int(input())
for _ in range(n):
	print(a, b)
	(x, y) = input().split()
	if a == x:
		a = y
	else:
		b = y
print(a, b)


ans = input().split()
n = int(input())
while n is not 0:
	print(ans[0], ans[1])
	(a, b) = input().split()
	ans[ans.index(a)] = b
	n -= 1
print(ans[0], ans[1])


st = input().split()
n = int(input())
l = [st]
e = st
for i in range(n):
	o = input().split()
	e = set(e) - {o[0]}
	e.add(o[1])
	l.append(list(e))
for i in l:
	print(' '.join(i))


import sys
import math
import bisect
import itertools

def main():
	ans = []
	A = input().split()
	ans.append(A.copy())
	n = int(input())
	for i in range(n):
		(s, t) = input().split()
		A.remove(s)
		A.append(t)
		ans.append(A.copy())
	for i in range(len(ans)):
		print(' '.join(ans[i]))
main()


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


def main():
	(pv1, pv2) = input().split()
	days = int(input())
	print(pv1, pv2)
	for i in range(days):
		(c, d) = input().split()
		if pv1 == c:
			pv1 = d
		elif pv2 == c:
			pv2 = d
		print(pv1, pv2)
main()


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))


a = [x for x in input().split()]
n = int(input())
print(a[0] + ' ' + a[1])
for i in range(n):
	(d, e) = [x for x in input().split()]
	if d == a[0]:
		a[0] = e
	else:
		a[1] = e
	print(a[0] + ' ' + a[1])


r = lambda : input().split()
(a, b) = r()
n = int(input())
print(a, b)
for _ in range(n):
	(x, y) = r()
	a = (a, y)[a == x]
	b = (b, y)[b == x]
	print(a, b)


a = input().split()
print(*a)
for _ in ' ' * int(input()):
	(b, c) = input().split()
	a[a.index(b)] = c
	print(*a)


init = input()
print(init)
init = init.split()
t = int(input())
for x in range(t):
	init += input().split()
	for y in init:
		if init.count(y) == 2:
			init.remove(y)
			init.remove(y)
	print(*init)


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


victims = input().split()
n = int(input())
print(*victims)
for i in range(n):
	(killed, victim) = input().split()
	victims.remove(killed)
	victims.append(victim)
	print(*victims)


def string_victims(list_victims):
	return list_victims[0] + ' ' + list_victims[1]

def get_next_victims(current_victims):
	(murdered, victim) = input().strip().split(' ')
	if murdered == current_victims[0]:
		return [victim, current_victims[1]]
	elif murdered == current_victims[1]:
		return [current_victims[0], victim]
victims = list(map(str, input().strip().split(' ')))
list_victims = [victims]
day = input().strip()
day = int(day)
for idx in range(0, day):
	x = get_next_victims(list_victims[len(list_victims) - 1])
	list_victims = list_victims + [x]
for x in list_victims:
	print(string_victims(x))


a = input().split()
n = int(input())
print(*a)
for i in range(n):
	(b, c) = input().split()
	a[a.index(b)] = c
	print(*a)


lista = input().split()
x = int(input())
vit1 = lista[0]
vit2 = lista[1]
print(vit1, vit2)
for i in range(x):
	lista2 = input().split()
	if vit1 == lista2[0]:
		vit1 = lista2[1]
	if vit2 == lista2[0]:
		vit2 = lista2[1]
	print(vit1, vit2)


victims = set(input().split())
print(*victims)
for _ in range(int(input())):
	(casualty, new_victim) = input().split()
	victims.discard(casualty)
	victims.add(new_victim)
	print(*victims)


initial = input().split()
n = int(input())
trans = []
print(initial[0], initial[1])
for i in range(n):
	next = input().split()
	if initial[0] == next[0]:
		print(next[1], initial[1])
		initial[0] = next[1]
	if initial[1] == next[0]:
		print(initial[0], next[1])
		initial[1] = next[1]


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


(a, b) = map(str, input().split())
n = int(input())
murdered = []
replaced = []
for i in range(n):
	(m, s) = map(str, input().split())
	murdered.append(m)
	replaced.append(s)
l1 = [a, b]
print(' '.join(l1))
for i in range(n):
	if murdered[i] == l1[0]:
		l1.remove(l1[0])
		l1.append(replaced[i])
		print(' '.join(l1))
	elif murdered[i] == l1[1]:
		l1.remove(l1[1])
		l1.append(replaced[i])
		print(' '.join(l1))


ans = input().split()
n = int(input())
print(*ans)
for _ in range(n):
	names = input().split()
	for i in range(2):
		if ans[i] == names[0]:
			ans[i] = names[1]
	print(*ans)


def Main():
	(X, Y) = map(str, input().split())
	print(X, Y)
	n = int(input())
	for _ in range(n):
		(A, B) = input().split()
		if X == A:
			X = B
		elif Y == A:
			Y = B
		print(X, Y)
Main()


initial = input()
n = int(input())
for i in range(n):
	line = input().split()
	print(initial)
	initial = initial.split()
	initial[initial.index(line[0])] = line[1]
	initial = ' '.join(initial)
print(initial)


string = input()
pairs = [string]
names = string.split()
n = int(input())
for x in range(n):
	string = input()
	temp = string.split()
	names.remove(temp[0])
	names.append(temp[1])
	pairs.append(' '.join(names))
for x in pairs:
	print(x)


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


f = input()
print(f)
h = f.split()
a = int(input())
for i in range(a):
	g = input()
	qq = g.split()
	if h[0] == qq[0]:
		h[0] = qq[1]
	else:
		h[1] = qq[1]
	print(' '.join(h))


(x, y) = input().split()
a = []
p = [x, y]
a.append(x + ' ' + y)
for i in range(int(input())):
	(m, n) = input().split()
	if m in p:
		p[p.index(m)] = n
	else:
		p[p.index(n)] = m
	a.append(p[0] + ' ' + p[1])
for i in a:
	print(i)


s = list(input().split())
print(*s)
n = int(input())
for i in range(n):
	ss = list(input().split())
	s.remove(ss[0])
	s.append(ss[1])
	print(*s)


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))


text = input().split()
print(*text)
for i in range(int(input())):
	(a, b) = input().split()
	text.remove(a)
	text.append(b)
	print(*text)


from sys import stdin, stdout, maxsize
tup = lambda : map(int, stdin.readline().split())
I = lambda : int(stdin.readline())
lint = lambda : [int(x) for x in stdin.readline().split()]
stpr = lambda x: stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
(a, b) = input().split()
print(a, b)
for _ in range(I()):
	(c, d) = input().split()
	if c == a:
		a = d
	else:
		b = d
	print(a, b)


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


(potential1, potential2) = input().split()
n = int(input())
print(potential1, potential2)
for i in range(n):
	(killed, newPotential) = input().split()
	if killed == potential1:
		potential1 = newPotential
	else:
		potential2 = newPotential
	print(potential1, potential2)


def prin(li):
	for j in li:
		print(j, end=' ')
	print()
li = list(map(str, input().split()))
n = int(input())
prin(li)
for i in range(0, n):
	(a, b) = map(str, input().split())
	if a == li[0]:
		li[0] = b
		prin(li)
	if a == li[1]:
		li[1] = b
		prin(li)


iv = input().split()
n = int(input())
print(' '.join(iv))
for _ in range(n):
	(k, r) = input().split()
	iv.remove(k)
	iv.append(r)
	print(' '.join(iv))


first = input().split()
n = int(input())
names = []
for i in range(n):
	names.append(tuple(input().split()))
print(' '.join(first))
for i in range(len(names)):
	if first[0] == names[i][0]:
		first[0] = names[i][1]
	else:
		first[1] = names[i][1]
	print(' '.join(first))


a = {*input().split()}
print(*a)
for _ in [0] * int(input()):
	(b, c) = input().split()
	a = a - {b} | {c}
	print(*a)


I = lambda : input().split()
n0 = I()
print(' '.join(n0))
for i in range(int(input())):
	n = I()
	n0[n0.index(n[0])] = n[1]
	print(' '.join(n0))


mat = input().split()
num = int(input())
res = ' '.join((i for i in mat)) + '\n'
for _ in range(num):
	sat = input().split()
	if mat[0] == sat[0]:
		mat[0] = sat[1]
	else:
		mat[1] = sat[1]
	res += ' '.join((i for i in mat)) + '\n'
print(res)


s = input().split()
n = int(input())
print(*s)
for i in range(n):
	k = input().split()
	s[s.index(k[0])] = k[1]
	print(*s)


names = input().split(' ')
days = int(input())
print(names[0] + ' ' + names[1])
for i in range(days):
	names2 = input().split(' ')
	if names2[0] == names[0]:
		names[0] = names2[1]
	else:
		names[1] = names2[1]
	print(names[0] + ' ' + names[1])


(one, two) = input().split()
print(one, two)
n = int(input())
for i in range(n):
	(kill, new) = input().split()
	if kill == one:
		one = new
	else:
		two = new
	print(one, two)


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


(str1, str2) = map(str, input().split())
n = int(input())
dict1 = {}
for x in range(n):
	(str3, str4) = map(str, input().split())
	dict1[str3] = str4
print(str1, str2)
for (key, values) in dict1.items():
	if key == str1:
		str1 = values
		print(str1, str2)
	else:
		str2 = values
		print(str1, str2)


(name1, name2) = input().lower().split(' ')
print(name1 + ' ' + name2)
n = int(input())
i = 0
while i < n:
	(victim1, victim2) = input().lower().split(' ')
	if name1 == victim1:
		name1 = victim2
	elif name2 == victim1:
		name2 = victim2
	print(name1 + ' ' + name2)
	i += 1


name = list(input().split())
print(name[0] + ' ' + name[1])
t = int(input().strip())
for i in range(t):
	next = list(input().split())
	if name[0] == next[0]:
		name[0] = next[1]
	else:
		name[1] = next[1]
	print(name[0] + ' ' + name[1])


(a, b) = input().split()
n = int(input())
last = (a, b)
print(a, b)
for i in range(n):
	s = input().split()
	x = 1 - last.index(s[0])
	last = (last[x], s[1])
	print(last[0], last[1], sep=' ')


ini = []
total = 0
ls = []

def inp():
	global ini, total, ls
	ini = input().split(' ')
	total = int(input())
	for i in range(total):
		ls.append(input().split(' '))

def printls(ls):
	print(ls[0] + ' ' + ls[1])

def solve():
	global ini, total, ls
	printls(ini)
	for pair in ls:
		xx = [i for i in ini + pair if (ini + pair).count(i) == 1]
		printls(list(xx))
		ini = list(xx)
inp()
solve()


s = input()
l = []
l.append(s)
s = s.split()
for i in range(int(input())):
	(a, b) = input().split()
	s[s.index(a)] = b
	l.append(' '.join(s))
print(*l, sep='\n')


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)


rip = input()
n = input()
n = int(n)
i = 0
while i < n:
	rip = rip + '\n' + input()
	i = i + 1
rip = rip.split('\n')
i = 0
while i < len(rip):
	rip[i] = rip[i].split(' ')
	i = i + 1
i = 1
print(rip[0][0], rip[0][1])
while i < len(rip):
	if rip[i][0] == rip[i - 1][0]:
		print(rip[i][1], rip[i - 1][1])
		rip[i][0] = rip[i - 1][1]
	else:
		print(rip[i][1], rip[i - 1][0])
		rip[i][0] = rip[i - 1][0]
	i = i + 1


(n1, n2) = input().split()
n = int(input())
while n > 0:
	print(n1, n2)
	(s1, s2) = input().split()
	if s1 == n1:
		n1 = s2
	else:
		n2 = s2
	n -= 1
print(n1, n2)


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


def main():
	from sys import stdin
	(a, b) = stdin.readline().split()
	n = int(stdin.readline().rstrip())
	print(a, b)
	for i in range(n):
		(k, s) = stdin.readline().split()
		if a == k:
			a = s
		else:
			b = s
		print(a, b)
main()


names = input().split()
print(*names)
n = int(input())
for i in range(0, n, 1):
	values = input().split()
	names.remove(values[0])
	names.insert(0, values[1])
	print(*names)


mesEl = list(input().split())
for i in range(int(input())):
	print(' '.join(mesEl))
	(a, b) = input().split()
	if mesEl[0] == a:
		mesEl[0] = b
	else:
		mesEl[1] = b
print(' '.join(mesEl))


(s1, s2) = input().split()
n = int(input())
for i in range(n):
	print(s1, s2)
	(t1, t2) = input().split()
	if s1 == t1:
		s1 = t2
	elif s1 == t2:
		s1 = t1
	elif s2 == t1:
		s2 = t2
	else:
		s2 = t1
print(s1, s2)


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


start = input()
n = int(input())
d = []
for i in range(n):
	r = input()
	d.append(r)
z = start
m = [z]
for i in range(n):
	y = m[i]
	for u in range(len(y)):
		if y[u] == ' ':
			a = u
	b = y[:a]
	c = y[a + 1:]
	e = d[i]
	for j in range(len(e)):
		if e[j] == ' ':
			f = j
	g = e[:f]
	h = e[f + 1:]
	if b == g:
		k = h + ' ' + c
		m.append(k)
	elif c == g:
		l = b + ' ' + h
		m.append(l)
for q in range(len(m)):
	print(m[q])


l = input().split()
print(*l)
n = int(input())
for i in range(n):
	(m, p) = input().split()
	l.remove(m)
	l.append(p)
	print(*l)


l = list(input().split())
print(*l, sep=' ')
n = int(input())
for _ in range(n):
	li = list(input().split())
	ind = l.index(li[0])
	l[ind] = li[1]
	print(*l, sep=' ')


(p1, p2) = input().split(' ')
print(p1, p2)
n = int(input())
for i in range(n):
	(morreu, trocou) = input().split(' ')
	if morreu == p1:
		p1 = trocou
		print(p1, p2)
	else:
		p2 = trocou
		print(p1, p2)


a = input().split()
n = int(input())
for i in range(n):
	print(' '.join(a))
	(ki, p) = input().split()
	if a[0] == ki:
		a[0] = p
	else:
		a[1] = p
print(' '.join(a))


l = list(map(str, input().split()))
n = int(input())
print(*l)
for i in range(n):
	(a2, b2) = map(str, input().split())
	l[l.index(a2)] = b2
	print(*l)


(s, t) = input().split()
print(s, t)
for i in range(int(input())):
	(u, v) = input().split()
	if s == u:
		s = v
	else:
		t = v
	print(s, t)


import sys
rl = lambda : sys.stdin.readline()
victims = rl().strip().split(' ')

def print_list():
	print('{} {}'.format(victims[0], victims[1]))
print_list()
num_line = int(rl())
for _ in range(num_line):
	(victim, subst) = rl().strip().split(' ')
	if victims[0] == victim:
		victims[0] = subst
	else:
		victims[1] = subst
	print_list()


R = lambda : map(int, input().split())
arr = input().split()
print(*arr)
(n,) = R()
for i in range(n):
	(x, y) = input().split()
	arr[arr.index(x)] = y
	print(*arr)


l1 = [n for n in input().split()]
m = int(input())
print(*l1, sep=' ')
for i in range(0, m):
	l = [k for k in input().split()]
	p = []
	for j in range(2):
		if l[j] not in l1:
			p.append(l[j])
		if l1[j] not in l:
			p.append(l1[j])
	print(*p, sep=' ')
	l1 = p


x = input()
p = x.split()
a = int(input())
array = []
for i in range(a):
	y = input()
	z = y.split()
	m = z[0]
	n = z[1]
	t = p.index(m)
	p[t] = n
	array.append(p[0])
	array.append(p[1])
print(x)
for i in range(0, a * 2, 2):
	print(array[i] + ' ' + array[i + 1])


s = input()
day = int(input())
victim = [s]
while day > 0:
	k = input().split()
	v = victim[-1].split()
	for x in range(len(v)):
		if v[x] == k[0]:
			v[x] = k[1]
	victim.append(' '.join(v))
	day -= 1
for y in victim:
	print(y)


(X, Y) = input().split()
print(X, Y)
N = int(input())
for i in range(N):
	(Z, M) = input().split()
	if X == Z:
		X = M
	else:
		Y = M
	print(X, Y)


(p1, p2) = input().split()
print(p1, p2)
tmp = {1: p1, 2: p2}
for i in range(int(input())):
	(m, r) = input().split()
	if tmp[1] == m:
		tmp[1] = r
		print(tmp[1], tmp[2])
	else:
		tmp[2] = r
		print(tmp[1], tmp[2])


s = set(input().split())
n = int(input())
print(*s)
for i in range(n):
	(a, b) = input().split()
	s ^= {a}
	s.add(b)
	print(*s)


from sys import *
from math import *
b = list(input().split())
n = int(input())
m = []
for i in range(n):
	a = list(input().split())
	m.append(a)
print(*b)
for i in range(n):
	if m[i][0] == b[0]:
		b[0] = m[i][1]
	else:
		b[1] = m[i][1]
	print(*b)


p = input().split(' ')
first = p[:]
n = int(input())
l = []
i = 0
while i < n:
	(h, k) = input().split(' ')
	p.remove(h)
	l.append(p[0])
	l.append(k)
	p.append(k)
	i += 1
print(first[0] + ' ' + first[1])
i = 0
while i < n * 2:
	print(l[i] + ' ' + l[i + 1])
	i += 2


import sys, math
from collections import deque

def solve():
	return
[a, b] = input().split()
n = int(input())
for i in range(n):
	print(a, b)
	[x, y] = input().split()
	if x == a:
		a = y
	else:
		b = y
print(a, b)


l = input().split()
n = int(input())
answ = [l.copy()]
for i in range(n):
	buf = input().split()
	l.remove(buf[0])
	l.append(buf[1])
	answ.append(l.copy())
for j in range(n + 1):
	print(answ[j][0], answ[j][1])


first = input().split(' ')
day = int(input())
tmp = []
tmp.append(first[0] + ' ' + first[1])
while day:
	second = input().split(' ')
	if first[0] == second[0]:
		tmp.append(first[1] + ' ' + second[1])
	else:
		tmp.append(first[0] + ' ' + second[1])
	first = tmp[-1].split(' ')
	day -= 1
for i in tmp:
	print(i)


a = input().split()
ans = [a[0], a[1]]
for i in ans:
	print(i, end=' ')
print()
n = int(input())
for i in range(n):
	l = input().split()
	if l[0] in ans:
		ans.remove(l[0])
		ans.append(l[1])
	elif l[1] in ans:
		ans.remove(l[1])
		ans.append(l[0])
	for i in ans:
		print(i, end=' ')
	print()


(a, b) = input().split()
print(a, b)
n = int(input())
for _ in range(n):
	(s1, s2) = input().split()
	if a == s1:
		a = s2
	else:
		b = s2
	print(a, b)


(x1, x2) = input().split()
n = int(input())
print(x1, x2)
for i in range(n):
	(y1, y2) = input().split()
	if x1 == y1:
		x1 = y2
	if x2 == y1:
		x2 = y2
	print(x1, x2)


(a, b) = list(map(str, input().split()))
k = int(input())
print(a, b)
for i in range(k):
	(g, d) = list(map(str, input().split()))
	if g == a:
		g = b
		print(g, d)
	else:
		g = a
		print(g, d)
	a = g
	b = d


l = input().split()
print(*l)
for i in range(int(input())):
	(s, t) = input().split()
	l[l.index(s)] = t
	print(*l)


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


p2 = str(input())
lst = []
lst.append(p2.split(' '))
num = int(input())
for i in range(num):
	lst.append(str(input()).split(' '))
for i in range(len(lst)):
	if i == 0:
		print(' '.join(lst[0]))
	elif lst[i][0] == lst[i - 1][0]:
		lst[i][0] = lst[i][1]
		lst[i][1] = lst[i - 1][1]
		print(' '.join(lst[i]))
	else:
		lst[i][0] = lst[i - 1][0]
		print(' '.join(lst[i]))


t = list(input().split())
print(*t)
for _ in range(int(input())):
	s = list(input().split())
	t.remove(s[0])
	t.append(s[1])
	print(*t)


from sys import stdin, stdout
names = set(stdin.readline().split())
n = int(stdin.readline())
ans = [list(names)]
for i in range(n):
	(first, second) = stdin.readline().split()
	names.discard(first)
	names.add(second)
	ans.append(list(names))
for i in range(n + 1):
	stdout.write(' '.join(ans[i]) + '\n')


inp = input().split(' ')
nam = []
nam.append(inp[0])
nam.append(inp[1])
final = []
final.append(nam)
n = int(input())
for i in range(n):
	name = final[-1].copy()
	k = input().split(' ')
	if name[0] == k[0]:
		name[0] = k[1]
	else:
		name[1] = k[1]
	final.append(name)
for i in final:
	print(*i)


day = [str(i) for i in input().split()]
n = int(input())
result = []
result.append(day.copy())
while n > 0:
	kill = [str(i) for i in input().split()]
	if kill[0] == day[0]:
		day[0] = kill[1]
	else:
		day[1] = kill[1]
	result.append(day.copy())
	n -= 1
for i in result:
	print(i[0], i[1])


(f, s) = input().split()
print(f, s)
n = int(input())
for _ in range(n):
	(killed, new) = input().split()
	if killed == f:
		f = new
		print(f, s)
	else:
		s = new
		print(f, s)


s = ' ' + input() + ' '
n = int(input())
print(s[1:-1])
for i in range(n):
	(l, r) = input().split()
	s = s.replace(' ' + l + ' ', ' ' + r + ' ')
	print(s[1:-1])


names = input().split()
n = int(input())
print(names[0] + ' ' + names[1])
for i in range(n):
	victims = input().split()
	names = list(set(victims + names) - set(victims).intersection(names))
	print(names[0] + ' ' + names[1])


v = input().split()
print(v[0] + ' ' + v[1])
n = int(input())
for i in range(n):
	d = input().split()
	v[v.index(d[0])] = d[1]
	print(v[0] + ' ' + v[1])


def serial_killer(first_pair, rest_pair):
	prev = first_pair.split()
	print('%s %s' % (prev[0], prev[1]))
	for each in rest_pair:
		curr = each.split()
		if curr[0] == prev[0]:
			prev = [prev[1], curr[1]]
		else:
			prev = [prev[0], curr[1]]
		print('%s %s' % (prev[0], curr[1]))

def main():
	names = input()
	name_pair = []
	for _ in range(int(input())):
		name_pair.append(input())
	serial_killer(names, name_pair)
main()


import sys
read = lambda : sys.stdin.readline().strip()
write = lambda x: sys.stdout.write(x + '\n')
pv = read().split()
N = int(read())
write(' '.join((v for v in pv)))
for _ in range(N):
	(nv, rv) = read().split()
	for i in range(2):
		if pv[i] == nv:
			pv[i] = rv
	write(' '.join((v for v in pv)))


text = []
text = input().split()
one = text[0]
two = text[1]
n = int(input())
print(one, two)
for x in range(n):
	text = input().split()
	if text[0] == one:
		one = text[1]
	elif text[0] == two:
		two = text[1]
	elif text[1] == one:
		one = text[0]
	elif text[1] == two:
		two = text[0]
	print(one, two)


(a, b) = input().strip().split(' ')
n = int(input().strip())
print('{} {}'.format(a, b))
for _ in range(n):
	(na, nb) = input().strip().split(' ')
	if a == na:
		a = nb
	elif b == na:
		b = nb
	print('{} {}'.format(a, b))


(t, v) = input().split(' ')
n = int(input())
i = 0
l = []
l1 = []
l1.append(t)
l1.append(v)
l.append(l1)
while i < n:
	(k1, k2) = input().split(' ')
	l1 = []
	if t == k1:
		l1.append(k2)
		l1.append(v)
		l.append(l1)
		t = v
		v = k2
	if v == k1:
		l1.append(k2)
		l1.append(t)
		l.append(l1)
		t = t
		v = k2
	i = i + 1
for i in l:
	print(i[0], i[1])


S = input().split()
N = int(input())
for i in range(N):
	print(' '.join(S))
	(s1, s2) = input().split()
	if s1 == S[0]:
		S[0] = s2
	elif s1 == S[1]:
		S[1] = s2
print(' '.join(S))


(p1, p2) = input().split()
n = int(input())
print(p1, p2)
for i in range(n):
	(vic, new) = input().split()
	if p1 == vic:
		p1 = new
	else:
		p2 = new
	print(p1, p2)


S = input().split()
N = int(input())
print(*S)
for _ in range(N):
	next_S = input().split()
	for i in range(4):
		p = i // 2
		q = i % 2
		if S[p] == next_S[q]:
			next_S[q] = S[p ^ 1]
			S = next_S
			print(*S)
			break
	else:
		assert False


import sys

def find_target_pair(prev, nex):
	new = [None, None]
	if prev[0] == nex[0]:
		new[1] = nex[1]
		new[0] = prev[1]
	elif prev[0] == nex[1]:
		new[1] = prev[1]
		new[0] = nex[0]
	if prev[1] == nex[0]:
		new[0] = prev[0]
		new[1] = nex[1]
	elif prev[1] == nex[1]:
		new[1] = prev[0]
		new[0] = nex[0]
	return new

def solution(prev, input):
	print(prev[0], prev[1])
	for pair in input:
		new = find_target_pair(prev, pair)
		print(new[0], new[1])
		prev = new
inp = list(sys.stdin.read().split('\n'))
prev = list(inp[0].split())
input = [i.split() for i in inp[2:-1]]
assert int(inp[1]) == len(input), 'Invalid input'
solution(prev, input)


a = []
a.append(list(input().split()))
n = int(input())
for _ in range(n):
	a.append(list(input().split()))
(x, y) = a[0]
print(x, y)
for i in range(1, n + 1):
	if a[i][0] == x:
		x = a[i][1]
	else:
		y = a[i][1]
	print(x, y)


from collections import deque

def main():
	from sys import stdin
	lines = deque((line.strip() for line in stdin.readlines()))
	(a, b) = lines.popleft().split()
	n = int(lines.popleft())
	print(a, b)
	for i in range(n):
		(killed, replace) = lines.popleft().split()
		if a == killed:
			a = replace
		else:
			b = replace
		print(a, b)
main()


(a, b) = input().split()
n = int(input())
print(a, b)
for i in range(n):
	(nex1, nex2) = input().split()
	if a == nex1:
		a = nex2
	elif b == nex1:
		b = nex2
	print(a, b)


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


names = input().split()
print(*names)
n = int(input())
for i in range(0, n, 1):
	(first, last) = input().split()
	names.remove(first)
	names.append(last)
	print(*names)


(prvni, druhy) = input().split()
N = int(input())
print(prvni, druhy)
for i in range(N):
	(mrtvy, novy) = input().split()
	if prvni == mrtvy:
		prvni = novy
	else:
		druhy = novy
	print(prvni, druhy)


data = set()
for el in input().split():
	data.add(el)
n = int(input())
for i in range(n):
	print(' '.join(data))
	(a, b) = input().split()
	data.remove(a)
	data.add(b)
print(' '.join(data))


l = []
temp = []
t = list(map(str, input().split()))
n = int(input())
print(*t)
for _ in range(n):
	(a, b) = map(str, input().split())
	if a not in t:
		if b == t[0]:
			t[0] = a
			print(*t)
		else:
			t[1] = a
			print(*t)
	elif a == t[0]:
		t[0] = b
		print(*t)
	else:
		t[1] = b
		print(*t)


y = list(map(str, input().split()))
x = int(input())
print(y[0], y[1])
for i in range(x):
	f = list(map(str, input().split()))
	y[y.index(f[0])] = f[1]
	print(y[0], y[1])


l = input().split()
n = int(input())
print(l[0], end=' ')
print(l[1])
for _ in range(n):
	(x, y) = input().split()
	l[l.index(x)] = y
	print(l[0], end=' ')
	print(l[1])


I = input
s = set(I().split())
print(*s)
for _ in range(int(I())):
	(d, n) = I().split()
	s = s - {d} | {n}
	print(*s)


l = list(map(str, input().split()))
m = []
m.append(l)
n = int(input())
for i in range(n):
	s = list(map(str, input().split()))
	m.append(s)
z = []
for i in range(n + 1):
	for j in range(2):
		if m[i][j] not in z:
			z.append(m[i][j])
			if len(z) == 2:
				print(' '.join(z))
		elif m[i][j] in z:
			z.remove(m[i][j])


nomes = input().split()
print(' '.join(nomes))
n = int(input())
for i in range(n):
	nl = input().split()
	nomes[nomes.index(nl[0])] = nl[1]
	print(' '.join(nomes))


(a, k) = map(str, input().split())
n = int(input())
l = ''
print(a + ' ' + k)
for i in range(n):
	(b, c) = map(str, input().split())
	if a == b:
		l = a.replace(b, c) + ' ' + k
		a = c
	else:
		l = a + ' ' + k.replace(b, c)
		k = c
	print(l)


Initial = list(input().split())
n = int(input())
print(*Initial, sep=' ')
for i in range(n):
	X = list(input().split())
	Initial[Initial.index(X[0])] = X[1]
	print(*Initial, sep=' ')


def printlist(a):
	print(' '.join(a))
a = input().split()
printlist(a)
n = int(input())
for _ in range(n):
	(x, y) = map(str, input().split())
	i = a.index(x)
	a[i] = y
	printlist(a)


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')


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


names = input().split()
n = int(input())
a = [names[:]]
for i in range(n):
	(c, d) = input().split()
	names.remove(c)
	names.append(d)
	a.append(names[:])
for i in a:
	print(i[0], i[1])


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)


class CodeforcesTask776ASolution:

	def __init__(self):
		self.result = ''
		self.pair = []
		self.n = 0
		self.murder_replace = []

	def read_input(self):
		self.pair = input().split(' ')
		self.n = int(input())
		for _ in range(self.n):
			self.murder_replace.append(input().split(' '))

	def process_task(self):
		res = []
		to_choose = set(self.pair)
		for day in self.murder_replace:
			res.append(' '.join(to_choose))
			to_choose.remove(day[0])
			to_choose.add(day[1])
		res.append(' '.join(to_choose))
		self.result = '\n'.join(res)

	def get_result(self):
		return self.result
Solution = CodeforcesTask776ASolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


import atexit, io, sys, collections, math, heapq, fractions, copy, os, functools
import sys
import random
import collections
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(a, b) = input().split(' ')
print(a, b)
for u in range(int(input())):
	(c, d) = input().split(' ')
	if a == c:
		a = d
	elif b == c:
		b = d
	print(a, b)


(a, b) = input().split()
count = int(input())
alive = set()
alive.add(a)
alive.add(b)
print(' '.join(alive))
for i in range(0, count):
	(d, r) = input().split()
	alive.remove(d)
	alive.add(r)
	print(' '.join(alive))


(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)


(victim1, victim2) = input().split()
n = int(input())
print(victim1, victim2)
for i in range(n):
	(scan1, scan2) = input().split()
	if scan1 == victim1:
		victim1 = scan2
	elif scan1 == victim2:
		victim2 = scan2
	print(victim1, victim2)