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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
void printarr(long long a[], long long n) {
  for (long long i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << "\n";
}
void printv(vector<long long> &v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
}
vector<long long> SieveOfEratosthenes(long long n) {
  bool prime[n + 1];
  memset(prime, true, sizeof(prime));
  for (long long p = 2; p * p <= n; p++) {
    if (prime[p] == true) {
      for (long long i = p * p; i <= n; i += p) prime[i] = false;
    }
  }
  vector<long long> ans;
  for (long long p = 2; p <= n; p++)
    if (prime[p]) ans.push_back(p);
  return ans;
}
vector<long long> res;
void factorize(long long n) {
  for (long long i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res.push_back(i);
      n /= i;
    }
  }
  if (n != 1) {
    res.push_back(n);
  }
}
vector<long long> divs;
void divisor(long long n) {
  for (long long i = 2; i <= sqrt(n); i++) {
    if (n % i == 0) {
      divs.push_back(i);
      if (n / i != i) {
        divs.push_back(n / i);
      }
    }
  }
  divs.push_back(1);
  if (n != 1) {
    divs.push_back(n);
  }
}
template <typename... T>
void re(T &...args) {
  ((cin >> args), ...);
}
bool checkLucky(long long n) {
  bool ans = true;
  while (n > 0) {
    long long r = n % 10;
    if (r != 4 && r != 7) {
      ans = false;
      break;
    }
    n = n / 10;
  }
  return ans;
}
long long decToBinary(long long n) {
  long long binaryNum[32];
  long long i = 0;
  while (n > 0) {
    binaryNum[i] = n % 2;
    n = n / 2;
    i++;
  }
  long long c = 0;
  for (long long j = i - 1; j >= 0; j--)
    if (binaryNum[j] == 1) c++;
  return c;
}
long long NoOFdig(long long n) {
  long long c = 0;
  while (n) {
    c++;
    n = n / 10;
  }
  return c;
}
long long nextNumDivByM(long long n, long long m) {
  if (n % m == 0) return n;
  return n - n % m + m;
}
long long sumTilln(long long n) { return 0.5 * n * (n + 1); }
long long sumOfSquaresTill(long long n) {
  return n * (n + 1) * (2 * n + 1) / 6;
}
bool f(long long x, long long y) { return x > y; }
void swap(long long *a, long long *b) {
  long long t = *a;
  *a = *b;
  *b = t;
}
long long remove2s(long long a) {
  while (a % 2 == 0) a /= 2;
  return a;
}
bool isPalindrome(string str) {
  long long l = 0;
  long long h = str.size() - 1;
  while (h > l) {
    if (str[l++] != str[h--]) {
      return false;
    }
  }
  return true;
}
long long sumofdigits(long long n) {
  long long sum = 0;
  while (n) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}
bool sortByStringLen(string s1, string s2) {
  return (long long)s1.size() < (long long)s2.size();
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  for (long long i = 2; i < n; i++)
    if (n % i == 0) return false;
  return true;
}
void solve() {
  long long q;
  re(q);
  map<string, string> a;
  string old, news;
  while (q--) {
    re(old, news);
    for (auto &it : a) {
      if (it.second == old) {
        it.second = news;
        goto l;
      }
    }
    a[old] = news;
  l:
    long long a1 = 1;
  }
  cout << a.size() << "\n";
  for (auto e : a) cout << e.first << ' ' << e.second << "\n";
}
int32_t main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << setprecision(100);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}