Misha hacked the Codeforces site. Then he decided to let all the users change their handles. A user can now change his handle any number of times. But each new handle must not be equal to any handle that is already used or that was used at some point.

Misha has a list of handle change requests. After completing the requests he wants to understand the relation between the original and the new handles of the users. Help him to do that.

Input

The first line contains integer q (1 ≤ q ≤ 1000), the number of handle change requests.

Next q lines contain the descriptions of the requests, one per line.

Each query consists of two non-empty strings old and new, separated by a space. The strings consist of lowercase and uppercase Latin letters and digits. Strings old and new are distinct. The lengths of the strings do not exceed 20.

The requests are given chronologically. In other words, by the moment of a query there is a single person with handle old, and handle new is not used and has not been used by anyone.

Output

In the first line output the integer n — the number of users that changed their handles at least once.

In the next n lines print the mapping between the old and the new handles of the users. Each of them must contain two strings, old and new, separated by a space, meaning that before the user had handle old, and after all the requests are completed, his handle is new. You may output lines in any order.

Each user who changes the handle must occur exactly once in this description.

Examples

Input

5
Misha ILoveCodeforces
Vasya Petrov
Petrov VasyaPetrov123
ILoveCodeforces MikeMirzayanov
Petya Ivanov


Output

3
Petya Ivanov
Misha MikeMirzayanov
Vasya VasyaPetrov123
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long fact(long long j) {
  long long a = 1;
  for (long long i = 1; i <= j; i++) a *= i;
  return a;
}
long long pw(long long a, long long b) {
  if (b == 0) return 1;
  if (b % 2)
    return pw(a, b - 1) * a;
  else {
    long long x = pw(a, b / 2);
    return x * x;
  }
}
long long sum2(long long c) {
  long long s = 0;
  while (c != 0) {
    s += (c % 10) * (c % 10);
    c /= 10;
  }
  return s;
}
vector<int> merge(const vector<int> &a, const vector<int> &b) {
  long long p1 = 0, p2 = 0;
  vector<int> c;
  for (; p1 < a.size() && p2 < b.size();)
    if (a[p1] == b[p2]) {
      c.push_back(a[p1]);
      p1++;
      p2++;
    } else if (a[p1] < b[p2])
      p1++;
    else
      p2++;
  return c;
}
bool prime(long long a) {
  if (a == 0 || a == 1) return false;
  for (int i = 2; i <= sqrt(a); i++)
    if (a % i == 0) return false;
  return true;
}
long long C(long long n, long long k) {
  vector<vector<long long>> dp(n + 1, vector<long long>(n + 1, 1));
  for (int i = 0; i < (n + 1); i++) {
    for (int j = 1; j < i; j++) {
      dp[i][j] = dp[i - 1][j - 1] + dp[i - 1][j];
    }
  }
  return dp[n][k];
}
struct st {
  int h, m, s;
};
bool operator<(st A, st B) {
  return (A.h < B.h || A.h == B.h && A.m < B.m ||
          A.h == B.h && A.m == B.m && A.s < B.s);
}
bool cmp(long long a, long long b) {
  if (a % 10 < b % 10) return true;
  if (a % 10 > b % 10) return false;
  if (a % 10 == b % 10) {
    return (a < b);
  }
}
long long phi(long long n) {
  long long ans = n;
  for (int i = 2; i * i <= n; i++)
    if (n % i == 0) {
      while (n % i == 0) n /= i;
      ans -= ans / i;
    }
  if (n > 1) ans -= ans / n;
  return ans;
}
vector<long long> rech(200005, 1);
void reh() {
  rech[0] = 0;
  rech[1] = 0;
  for (long long i = 2; i < 100000; i++)
    for (long long j = i * i; j < 100000; j += i)
      if (rech[j]) rech[j] = 0;
}
struct Node {
  long long i, mx;
};
Node tr[4 * 1000000 + 10];
void build(vector<long long> &a, long long v, long long l, long long r) {
  if (l == r)
    tr[v].i = l, tr[v].mx = a[l];
  else {
    long long m = (l + r) / 2;
    build(a, 2 * v, l, m);
    build(a, 2 * v + 1, m + 1, r);
    if (tr[2 * v].mx >= tr[2 * v + 1].mx)
      tr[v].i = tr[2 * v].i, tr[v].mx = tr[2 * v].mx;
    else
      tr[v].i = tr[2 * v + 1].i, tr[v].mx = tr[2 * v + 1].mx;
  }
}
Node find(long long x, long long y, long long v, long long l, long long r) {
  if (x == l && y == r) return tr[v];
  long long m = (l + r) / 2;
  if (y <= m)
    return find(x, y, 2 * v, l, m);
  else if (x > m)
    return find(x, y, 2 * v + 1, m + 1, r);
  else {
    Node a, b, c;
    a = find(x, m, 2 * v, l, m);
    b = find(m + 1, y, 2 * v + 1, m + 1, r);
    if (a.mx >= b.mx)
      c.i = a.i, c.mx = a.mx;
    else
      c.i = b.i, c.mx = b.mx;
    return c;
  }
}
void update(long long i, long long x, long long v, long long l, long long r) {
  if (l == r) {
    if (tr[v].mx != 0)
      tr[v].mx = x;
    else
      return;
  } else {
    long long m = (l + r) / 2;
    if (i <= m)
      update(i, x, 2 * v, l, m);
    else
      update(i, x, 2 * v + 1, m + 1, r);
    if (tr[2 * v].mx >= tr[2 * v + 1].mx)
      tr[v].i = tr[2 * v].i, tr[v].mx = tr[2 * v].mx;
    else
      tr[v].i = tr[2 * v + 1].i, tr[v].mx = tr[2 * v + 1].mx;
  }
}
vector<long long> u(100001, 0);
void way(long long x, long long n, vector<vector<long long>> &a, long long &l,
         long long &k) {
  long long s = 0;
  for (int i = 1; i <= n; i++)
    if (a[x][i] && !u[i]) {
      l++;
      s++;
      u[i] = 1;
      way(i, n, a, l, k);
      u[i] = 0;
    }
  if (!s) k++;
}
string dectobin(long long n) {
  string s;
  while (n) {
    s += n % 2 + '0';
    n /= 2;
  }
  reverse(s.begin(), s.end());
  return s;
}
long long bintodec(string s) {
  long long n = 0;
  for (int i = 0; i < s.length(); i++) {
    n += (s[i] - '0') * pw(2, s.length() - i - 1);
  }
  return n;
}
long long tree[1000000];
void bt(vector<long long> &a, long long l, long long r, long long v) {
  if (l == r)
    tree[v] = a[l];
  else {
    long long m = (l + r) / 2;
    bt(a, l, m, 2 * v);
    bt(a, m + 1, r, 2 * v + 1);
    tree[v] = tree[2 * v] + tree[2 * v + 1] - 1;
  }
}
long long fit(long long x, long long y, long long l, long long r, long long v) {
  if (x == l && y == r) return tree[v];
  long long m = (l + r) / 2;
  if (y <= m)
    return fit(x, y, l, m, 2 * v);
  else if (x > m)
    return fit(x, y, m + 1, r, 2 * v + 1);
  else
    return max(fit(x, m, l, m, 2 * v), fit(m + 1, y, m + 1, r, 2 * v + 1));
}
vector<bool> use(400000, 0);
vector<int> w(400000, 0);
vector<vector<long long>> g(400000);
string s;
bool cdfs(long long v) {
  w[v] = 1;
  for (int i = 0; i < g[v].size(); i++) {
    if (w[g[v][i]] == 1) {
      return true;
    } else if (w[g[v][i]] == 0) {
      if (cdfs(g[v][i])) return true;
    }
  }
  w[v] = 2;
  return false;
}
long long ans = 0;
void rdfs(long long v, string a) {
  a += s[v - 1];
  for (int i = 0; i < g[v].size(); i++) {
    if (w[g[v][i]] != 1) {
      rdfs(g[v][i], a);
    }
  }
  if (g[v].size() == 0) {
    long long k = 1;
    sort(a.begin(), a.end());
    for (int i = 1; i < (a.length()); i++) {
      if (a[i] == a[i - 1])
        k++;
      else
        ans = max(ans, k), k = 1;
    }
    ans = max(k, ans);
  }
  w[v] = 2;
}
long long sum(long long k, long long v) {
  long long s = 0, q = 1;
  while (v / q > 0) {
    s += v / q;
    q *= k;
  }
  return s;
}
long long bn(long long l, long long r, long long k, long long n) {
  if (l == r) return l;
  long long m = (l + r) / 2;
  long long s1 = sum(k, m);
  if (s1 > n)
    bn(l, m, k, n);
  else if (s1 < n)
    bn(m + 1, r, k, n);
  else
    return m;
}
vector<long long> a(1000001, 0);
long long f(long long x) {
  if (x < 10) return x;
  long long d = 1;
  while (x) {
    if (x % 10) d *= x % 10;
    x /= 10;
  }
  if (a[d] != 0) return a[d];
  return f(d);
}
int main() {
  long long n;
  cin >> n;
  vector<pair<string, string>> a;
  for (int i = 0; i < (n); i++) {
    string old, ne;
    cin >> old >> ne;
    bool t = 0;
    int k = 0;
    for (int j = 0; j < (a.size()); j++) {
      if (a[j].second == old) t = 1, k = j;
    }
    if (t) {
      a[k].second = ne;
    } else
      a.push_back({old, ne});
  }
  cout << a.size() << endl;
  for (int i = 0; i < (a.size()); i++) {
    cout << a[i].first << " " << a[i].second << endl;
  }
  return 0;
}
