wwwww w
8
wwwww wwwwwwww
wwwwwwww wwwwwwwww
wwwwwwwww wwwwwwwwww
w www
wwwwwwwwww wwww
wwww ww
www wwwwww
wwwwww wwwwwww
 k d
17
k l
d v
v z
l r
z i
r s
s p
p w
w j
j h
i c
h m
m q
c o
o g
q x
x n
 wxz hbeqwqp
7
hbeqwqp cpieghnszh
cpieghnszh tlqrpd
tlqrpd ttwrtio
ttwrtio xapvds
xapvds zk
wxz yryk
zk b
 ze udggmyop
4
ze szhrbmft
udggmyop mjorab
szhrbmft ojdtfnzxj
ojdtfnzxj yjlkg
 bwyplnjn zkms
26
zkms nzmcsytxh
nzmcsytxh yujsb
bwyplnjn gtbzhudpb
gtbzhudpb hpk
yujsb xvy
hpk wrwnfokml
wrwnfokml ndouuikw
ndouuikw ucgrja
ucgrja tgfmpldz
xvy nycrfphn
nycrfphn quvs
quvs htdy
htdy k
tgfmpldz xtdpkxm
xtdpkxm suwqxs
k fv
suwqxs qckllwy
qckllwy diun
fv lefa
lefa gdoqjysx
diun dhpz
gdoqjysx bdmqdyt
dhpz dgz
dgz v
bdmqdyt aswy
aswy ydkayhlrnm
 iii iiiiii
7
iii iiiiiiiiii
iiiiiiiiii iiii
iiii i
iiiiii iiiiiiii
iiiiiiii iiiiiiiii
i iiiii
iiiii ii
 wced gnsgv
23
gnsgv japawpaf
japawpaf nnvpeu
nnvpeu a
a ddupputljq
ddupputljq qyhnvbh
qyhnvbh pqwijl
wced khuvs
khuvs bjkh
pqwijl ysacmboc
bjkh srf
srf jknoz
jknoz hodf
ysacmboc xqtkoyh
hodf rfp
xqtkoyh bivgnwqvoe
bivgnwqvoe nknf
nknf wuig
rfp e
e bqqknq
wuig sznhhhu
bqqknq dhrtdld
dhrtdld n
sznhhhu bguylf
 a b
3
a c
b d
d e
 q s
10
q b
b j
s g
j f
f m
g c
c a
m d
d z
z o
 qqqqqqqqqq qqqqqqqq
3
qqqqqqqq qqqqqqqqq
qqqqqqqqq qqqqq
qqqqq q

wwwww w
wwwwwwww w
wwwwwwwww w
wwwwwwwwww w
wwwwwwwwww www
wwww www
ww www
ww wwwwww
ww wwwwwww
 k d
l d
l v
l z
r z
r i
s i
p i
w i
j i
h i
h c
m c
q c
q o
q g
x g
n g
 wxz hbeqwqp
wxz cpieghnszh
wxz tlqrpd
wxz ttwrtio
wxz xapvds
wxz zk
yryk zk
yryk b
 ze udggmyop
szhrbmft udggmyop
szhrbmft mjorab
ojdtfnzxj mjorab
yjlkg mjorab
 bwyplnjn zkms
bwyplnjn nzmcsytxh
bwyplnjn yujsb
gtbzhudpb yujsb
hpk yujsb
hpk xvy
wrwnfokml xvy
ndouuikw xvy
ucgrja xvy
tgfmpldz xvy
tgfmpldz nycrfphn
tgfmpldz quvs
tgfmpldz htdy
tgfmpldz k
xtdpkxm k
suwqxs k
suwqxs fv
qckllwy fv
diun fv
diun lefa
diun gdoqjysx
dhpz gdoqjysx
dhpz bdmqdyt
dgz bdmqdyt
v bdmqdyt
v aswy
v ydkayhlrnm
 iii iiiiii
iiiiiiiiii iiiiii
iiii iiiiii
i iiiiii
i iiiiiiii
i iiiiiiiii
iiiii iiiiiiiii
ii iiiiiiiii
 wced gnsgv
wced japawpaf
wced nnvpeu
wced a
wced ddupputljq
wced qyhnvbh
wced pqwijl
khuvs pqwijl
bjkh pqwijl
bjkh ysacmboc
srf ysacmboc
jknoz ysacmboc
hodf ysacmboc
hodf xqtkoyh
rfp xqtkoyh
rfp bivgnwqvoe
rfp nknf
rfp wuig
e wuig
bqqknq wuig
bqqknq sznhhhu
dhrtdld sznhhhu
n sznhhhu
n bguylf
 a b
c b
c d
c e
 q s
b s
j s
j g
f g
m g
m c
m a
d a
z a
o a
 qqqqqqqqqq qqqqqqqq
qqqqqqqqqq qqqqqqqqq
qqqqqqqqqq qqqqq
qqqqqqqqqq q

#!/usr/bin/python
# coding: utf-8

(pv1,pv2)=raw_input().split(' ')
n=int(raw_input())
print pv1, pv2
for i in xrange(n):
    (murdered,replaced)=raw_input().split(' ')
    if(pv1==murdered):
        pv1=replaced
    elif(pv2==murdered):
        pv2=replaced
    print pv1, pv2


'''

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.

'''
