Problem: 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. 

Solution (in CPP):

Solution:
#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;
}