#include <bits/stdc++.h>
using namespace std;
namespace {
int CC_;
const double EPS = 1E-9;
const double PI = 2 * acos(0.0);
const long long MOD = 1000000007;
template <class T>
void DA(T i, T e) {
  while (i != e) {
    cout << "Con>>( " << ++CC_ << " ) " << *i++ << endl;
  }
}
template <class T>
void DA(T* x, int l) {
  for (int i = 0; i < l; i++) cout << "[" << i << "]>> " << x[i] << endl;
}
template <class T>
inline void sary(T* st, T* nd) {
  while (st < nd) cin >> *st++;
}
template <class T>
void tobin(T n, char* bin) {
  int pos = 1 << ((int)log2(n));
  while (pos >= 1) {
    if ((n & pos) == 0)
      *bin = '0';
    else
      *bin = '1';
    pos >>= 1;
    bin++;
  }
  *bin = '\0';
}
template <class T>
inline T LCM(T x, T y) {
  return ((x * y) / __gcd(x, y));
}
long long todec(string& num, int b) {
  long long dec = num[0] - (isupper(num[0]) ? 'A' - 10 : '0');
  for (int i = 1; num[i]; i++) {
    if (num[i] >= 'A' && num[i] <= 'Z')
      num[i] -= 'A' - 10;
    else
      num[i] -= '0';
    dec *= b;
    dec += num[i];
  }
  return dec;
}
long long bigMod(long long x, long long y, long long m) {
  if (y == 0) return 1;
  long long p = bigMod(x, y / 2, m) % m;
  p = (p * p) % m;
  return ((y & 1) ? (x * p) % m : p);
}
unsigned long long ncr(int n, int k) {
  unsigned long long res = 1;
  if (k > n - k) k = n - k;
  for (int i = 0; i < k; i++) {
    res *= n - i;
    res /= i + 1;
  }
  return res;
}
int phi(int n) {
  int ret = n;
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) {
      while (n % i == 0) {
        n /= i;
      }
      ret -= ret / i;
    }
  }
  if (n > 1) ret -= ret / n;
  return ret;
}
int egcd(int a, int b, int& x, int& y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  int x1, y1;
  int gcd = egcd(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
}
bool comp(const int a, const int b) { return a > b; }
}  // namespace
const int sss = 1E6;
string nxt[1005], mu[1005];
string mm[1005][2];
void solve(void) {
  int n;
  string a, b;
  cin >> a >> b >> n;
  for (int i = 0; i < n; i++) {
    cin >> mu[i] >> nxt[i];
  }
  mm[0][0] = a;
  mm[0][1] = b;
  string tmp;
  for (int i = 1; i <= n; i++) {
    tmp = mu[i - 1];
    int j = 0;
    mm[i][0] = nxt[i - 1];
    if (mm[i - 1][0] == tmp)
      mm[i][1] = mm[i - 1][1];
    else
      mm[i][1] = mm[i - 1][0];
  }
  for (int i = 0; i <= n; i++) {
    cout << mm[i][0] << " " << mm[i][1] << endl;
  }
}
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
