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

import java.io.File;import java.io.FileInputStream;import java.io.FileNotFoundException;
import java.io.IOException;import java.io.PrintStream;import java.io.PrintWriter;
import java.security.AccessControlException;import java.util.Arrays;import java.util.Collection;
import java.util.Comparator;import java.util.List;import java.util.Map;import java.util.Objects;
import java.util.Scanner;import java.util.TreeMap;import java.util.TreeSet;import java.util.function.Function;
import java.util.stream.Collectors;import java.util.stream.IntStream;import java.util.stream.LongStream;
import java.util.stream.Stream;public class _p000776A {static public void main(final String[] args) 
throws IOException{p000776A._main(args);}
static private class p000776A extends Solver{public p000776A(){nameIn="in/900/p000776A.in"
;singleTest=true;}@Override public void solve()throws IOException{String[]n0=lineToArray
();int n=sc.nextInt();if(sc.hasNextLine()){sc.nextLine();}TreeSet<String>set=new
 TreeSet<>();set.addAll(list(n0));for(int _if0=0;_if0<n;_if0++){String n1=sc.next
();String n2=sc.next();if(sc.hasNextLine()){sc.nextLine();}pw.println(join(set))
;set.remove(n1);set.add(n2);}pw.println(join(set));}static public void _main(String
[]args)throws IOException{new p000776A().run();}}static private class Pair<K,V>{
private K k;private V v;public Pair(final K t,final V u){this.k=t;this.v=u;}public
 K getKey(){return k;}public V getValue(){return v;}}static private abstract class
 Solver{protected String nameIn=null;protected String nameOut=null;protected boolean
 singleTest=false;protected boolean preprocessDebug=false;protected boolean doNotPreprocess
=false;protected PrintStream debugPrintStream=null;protected Scanner sc=null;protected
 PrintWriter pw=null;final static String SPACE=" ";final static String SPACES="\\s+"
;private void process()throws IOException{if(!singleTest){int t=lineToIntArray()
[0];while(t-->0){solve();}}else{solve();}}abstract protected void solve()throws 
IOException;protected String[]lineToArray()throws IOException{return sc.nextLine
().trim().split(SPACES);}protected int[]lineToIntArray()throws IOException{return
 Arrays.stream(lineToArray()).mapToInt(Integer::valueOf).toArray();}protected long
[]lineToLongArray()throws IOException{return Arrays.stream(lineToArray()).mapToLong
(Long::valueOf).toArray();}protected void run()throws IOException{boolean done=false
;try{if(nameIn!=null && new File(nameIn).exists()){try(FileInputStream fis=new FileInputStream
(nameIn);PrintWriter pw0=select_output();){done=true;sc=new Scanner(fis);pw=pw0;
process();}}}catch(IOException ex){}catch(AccessControlException ex){}if(!done){
try(PrintWriter pw0=select_output();){sc=new Scanner(System.in);pw=pw0;process()
;}}}private PrintWriter select_output()throws FileNotFoundException{if(nameOut!=
null){return new PrintWriter(nameOut);}return new PrintWriter(System.out);}public
 static Map<Integer,List<Integer>>mapi(final int[]a){return IntStream.range(0,a.
length).collect(()->new TreeMap<Integer,List<Integer>>(),(res,i)->{if(!res.containsKey
(a[i])){res.put(a[i],Stream.of(i).collect(Collectors.toList()));}else{res.get(a[
i]).add(i);}},Map::putAll);}public static Map<Long,List<Integer>>mapi(final long
[]a){return IntStream.range(0,a.length).collect(()->new TreeMap<Long,List<Integer
>>(),(res,i)->{if(!res.containsKey(a[i])){res.put(a[i],Stream.of(i).collect(Collectors
.toList()));}else{res.get(a[i]).add(i);}},Map::putAll);}public static<T>Map<T,List
<Integer>>mapi(final T[]a){return IntStream.range(0,a.length).collect(()->new TreeMap
<T,List<Integer>>(),(res,i)->{if(!res.containsKey(a[i])){res.put(a[i],Stream.of(
i).collect(Collectors.toList()));}else{res.get(a[i]).add(i);}},Map::putAll);}public
 static<T>Map<T,List<Integer>>mapi(final T[]a,Comparator<T>cmp){return IntStream
.range(0,a.length).collect(()->new TreeMap<T,List<Integer>>(cmp),(res,i)->{if(!res
.containsKey(a[i])){res.put(a[i],Stream.of(i).collect(Collectors.toList()));}else
{res.get(a[i]).add(i);}},Map::putAll);}public static Map<Integer,List<Integer>>mapi
(final IntStream a){int[]i=new int[]{0};return a.collect(()->new TreeMap<Integer
,List<Integer>>(),(res,v)->{if(!res.containsKey(v)){res.put(v,Stream.of(i[0]).collect
(Collectors.toList()));}else{res.get(v).add(i[0]);}i[0]++;},Map::putAll);}public
 static Map<Long,List<Integer>>mapi(final LongStream a){int[]i=new int[]{0};return
 a.collect(()->new TreeMap<Long,List<Integer>>(),(res,v)->{if(!res.containsKey(v
)){res.put(v,Stream.of(i[0]).collect(Collectors.toList()));}else{res.get(v).add(
i[0]);}i[0]++;},Map::putAll);}public static<T>Map<T,List<Integer>>mapi(final Stream
<T>a,Comparator<T>cmp){int[]i=new int[]{0};return a.collect(()->new TreeMap<T,List
<Integer>>(cmp),(res,v)->{if(!res.containsKey(v)){res.put(v,Stream.of(i[0]).collect
(Collectors.toList()));}else{res.get(v).add(i[0]);}},Map::putAll);}public static
<T>Map<T,List<Integer>>mapi(final Stream<T>a){int[]i=new int[]{0};return a.collect
(()->new TreeMap<T,List<Integer>>(),(res,v)->{if(!res.containsKey(v)){res.put(v,
Stream.of(i[0]).collect(Collectors.toList()));}else{res.get(v).add(i[0]);}},Map::
putAll);}public static List<int[]>listi(final int[]a){return IntStream.range(0,a
.length).mapToObj(i->new int[]{a[i],i}).collect(Collectors.toList());}public static
 List<long[]>listi(final long[]a){return IntStream.range(0,a.length).mapToObj(i->
new long[]{a[i],i}).collect(Collectors.toList());}public static<T>List<Pair<T,Integer
>>listi(final T[]a){return IntStream.range(0,a.length).mapToObj(i->new Pair<T,Integer
>(a[i],i)).collect(Collectors.toList());}public static List<int[]>listi(final IntStream
 a){int[]i=new int[]{0};return a.mapToObj(v->new int[]{v,i[0]++}).collect(Collectors
.toList());}public static List<long[]>listi(final LongStream a){int[]i=new int[]
{0};return a.mapToObj(v->new long[]{v,i[0]++}).collect(Collectors.toList());}public
 static<T>List<Pair<T,Integer>>listi(final Stream<T>a){int[]i=new int[]{0};return
 a.map(v->new Pair<T,Integer>(v,i[0]++)).collect(Collectors.toList());}public static
 String join(final int[]a){return Arrays.stream(a).mapToObj(Integer::toString).collect
(Collectors.joining(SPACE));}public static String join(final long[]a){return Arrays
.stream(a).mapToObj(Long::toString).collect(Collectors.joining(SPACE));}public static
<T>String join(final T[]a){return Arrays.stream(a).map(v->Objects.toString(v)).collect
(Collectors.joining(SPACE));}public static<T>String join(final T[]a,final Function
<T,String>toString){return Arrays.stream(a).map(v->toString.apply(v)).collect(Collectors
.joining(SPACE));}public static<T>String join(final Collection<T>a){return a.stream
().map(v->Objects.toString(v)).collect(Collectors.joining(SPACE));}public static
<T>String join(final Collection<T>a,final Function<T,String>toString){return a.stream
().map(v->toString.apply(v)).collect(Collectors.joining(SPACE));}public static<T
>String join(final Stream<T>a){return a.map(v->Objects.toString(v)).collect(Collectors
.joining(SPACE));}public static<T>String join(final Stream<T>a,final Function<T,
String>toString){return a.map(v->toString.apply(v)).collect(Collectors.joining(SPACE
));}public static<T>String join(final IntStream a){return a.mapToObj(Integer::toString
).collect(Collectors.joining(SPACE));}public static<T>String join(final LongStream
 a){return a.mapToObj(Long::toString).collect(Collectors.joining(SPACE));}public
 static List<Integer>list(final int[]a){return Arrays.stream(a).mapToObj(Integer
::valueOf).collect(Collectors.toList());}public static List<Integer>list(final IntStream
 a){return a.mapToObj(Integer::valueOf).collect(Collectors.toList());}public static
 List<Long>list(final long[]a){return Arrays.stream(a).mapToObj(Long::valueOf).collect
(Collectors.toList());}public static List<Long>list(final LongStream a){return a
.mapToObj(Long::valueOf).collect(Collectors.toList());}public static<T>List<T>list
(final Stream<T>a){return a.collect(Collectors.toList());}public static<T>List<T
>list(final T[]a){return Arrays.stream(a).collect(Collectors.toList());}}}
