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.

题意:看样列

解法:没啥说的

 #include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
using namespace std;
int main(){
string s1,s2;
cin>>s1>>s2;
cout<<s1<<" "<<s2<<endl;
int n;
cin>>n;
for(int i=;i<=n;i++){
string s3,s4;
cin>>s3>>s4;
if(s3==s1){
s1=s4;
}else{
s2=s4;
}
cout<<s1<<" "<<s2<<endl;
}
return ;
}

最新文章

  1. 洛谷 P1330 封锁阳光大学 Label:染色问题
  2. Newtonsoft.Json(Json.net)的基本用法
  3. Chapter6: question 43 - 45
  4. Public and Private Interfaces in ruby
  5. 【转】ffmpeg参数中文详细解释
  6. Oracle基础 (十三)日期函数
  7. Android 图片处理效果集
  8. Jasmine 的自定义部分
  9. 一次关于mongodb性能踩坑的总结
  10. SpringCloud @FeignClient的类注解@ReqestMapping无效报错:No message available&quot;,&quot;path&quot;:&quot;/xxxx
  11. Hello——Java10新特性,请了解一下
  12. IDEA同步上传lua代码,方便开发。
  13. Java面试题和解答(四)
  14. 例:三位老师对某次数学竞赛进行了预测,他们的预测如下:   甲:学生A得了第一名,学生B得第三名。   乙:学生C得了第一名,学生D得第四名。   丙:学生D得了第二名,学生A得第三名。 结果表明,他们都说对了一半,说错了一半,并且无并列名次,输出A、B、C和D各自的名次。
  15. idea实用插件
  16. Python3 系列之 环境配置篇
  17. nodejs 学习四 处理回调地狱
  18. 将svn下载的项目转化为java project
  19. 《DSP using MATLAB》Problem 5.9
  20. gaea-editor 项目使用

热门文章

  1. LightOJ - 1027 A Dangerous Maze —— 期望
  2. springmvc junit测试
  3. RAM的分类
  4. CodeForces960F:Pathwalks (主席树+DP)
  5. C语言解释器的实现--存储结构(一)
  6. JAVA 需要理解的重点 二
  7. 将DotNetBar添加到工具箱中
  8. jni中c代码调用java代码
  9. why ftp服务器采用多进程模式
  10. Struts过滤器