#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int n;
  cin >> n;
  cout << a << " " << b << "\n";
  while (n--) {
    string x, y;
    cin >> x >> y;
    if (x == a)
      a = y;
    else
      b = y;
    cout << a << " " << b;
    if (n) cout << "\n";
  }
}
