x, y = input().split()
print(x, y)
for _ in range(int(input())):
a, b = input().split()
if x == a:
x = b
elif y == a:
y = b
print(x, y)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define pb push_back
#define endl '\n'
#define all(v) v.begin(), v.end()
#define fr(m,n) for(i=m;i<n;i++)
#define frr(m,n) for(i=m-1;i>=n;i--)
#define ffr1 for(i=n;i>=1;i--)
#define ffr for(i=n-1;i>=0;i--)
#define ff for(i=0;i<n;i++)
#define ff1 for(i=1;i<=n;i++)
#define frj(m,n) for(j=m;j<n;j++)
#define frl(m,n) for(l=m;l<n;l++)
#define frd(m,n) for(d=m;d<n;d++)
#define yes cout << "YES"
#define no cout << "NO"
#define yesm cout << "Yes"
#define nom cout << "No"
#define inf INT_MAX
#define ext {cout << -1; return;}
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define rall(a) a.rbegin(),a.rend()
#define vi vector<int>
#define pi pair<int,int>
#define vvi vector<vi>
#define vc vector<char>
#define vb vector<bool>
#define vs vector<string>
#define ss set<string>
#define vpi vector<pi>
#define mii map<int,int>
#define mci map<char,int>
#define als(i) cout << i.fi << " " << i.se << endl
#define si set<int>
#define sc set<char>
#define fi first
#define wq while(q--)
#define se second
#define sz size()
#define el cout<<endl
bool id = 0, id1 = 0, id2 = 0;
int x = 0, y = 0, z = 0, type, tp;
int ans = 0, num = 0, sum = 0, mo = 0, me = 0, cnt = 0, mi = inf, ma = 0;
string s, p, st;
int h = 0, w = 0, n = 0, m = 0, t = 0, k = 0, i = 0, j = 0, l = 0, r = 0, q = 0, a = 0, b = 0, c = 0, d = 0;
const int mod = 1e9 + 7;
// const int mod = 998244353;
ll fac(ll n) {ll ans = 1; for (int i = 1; i <= n; ++i) {ans = ans * i;} return ans;}
bool cprime(ll n) {if (n <= 1)return false; if (n <= 3)return true; if (n % 2 == 0 || n % 3 == 0)return false; for (int i = 5; i * i <= n; i = i + 6)if (n % i == 0 || n % (i + 2) == 0)return false; return true;}
int binpow(int x, int y) {int z = 1; while (y) {if (y & 1) z = z * x % mod; x = x * x % mod; y >>= 1;} return z;}
int inv(int x) {return binpow(x, mod - 2);}
int bintoint(string s) {reverse(all(s)); int xx = 0; int m = 1; frj(0, s.sz) {xx += (s[j] == '1' ? m : 0); m <<= 1;} return xx;}
string inttobin(int x) {string s; while (x) {s += (x & 1) + '0';} reverse(all(s)); return s;}
void solve() {
cin >> s >> p;
// string q;
cin >> n;
set<string>q;
q.insert(s);
q.insert(p);
for (auto l : q) cout << l << " "; el;
ff{
cin >> s >> p;
if (q.find(s) != q.end()) {
q.erase(s);
q.insert(p);
}
else{
q.erase(p);
q.insert(s);
}
for (auto l : q) cout << l << " "; el;
}
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
int T = 1;
// cin >> T;
while (T--) {
cout << fixed << setprecision(12); solve();
cout << endl;
} return 0;
}
1440A - Buy the String | 1658F - Juju and Binary String |
478A - Initial Bet | 981A - Antipalindrome |
365A - Good Number | 1204B - Mislove Has Lost an Array |
1409D - Decrease the Sum of Digits | 1476E - Pattern Matching |
1107A - Digits Sequence Dividing | 1348A - Phoenix and Balance |
1343B - Balanced Array | 1186A - Vus the Cossack and a Contest |
1494A - ABC String | 1606A - AB Balance |
1658C - Shinju and the Lost Permutation | 1547C - Pair Programming |
550A - Two Substrings | 797B - Odd sum |
1093A - Dice Rolling | 1360B - Honest Coach |
1399C - Boats Competition | 1609C - Complex Market Analysis |
1657E - Star MST | 1143B - Nirvana |
1285A - Mezo Playing Zoma | 919B - Perfect Number |
894A - QAQ | 1551A - Polycarp and Coins |
313A - Ilya and Bank Account | 1469A - Regular Bracket Sequence |