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;
template <class T>
bool umin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool umax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
long long FIRSTTRUE(function<bool(long long)> f, long long lb, long long rb) {
  while (lb < rb) {
    long long mb = (lb + rb) / 2;
    f(mb) ? rb = mb : lb = mb + 1;
  }
  return lb;
}
long long LASTTRUE(function<bool(long long)> f, long long lb, long long rb) {
  while (lb < rb) {
    long long mb = (lb + rb + 1) / 2;
    f(mb) ? lb = mb : rb = mb - 1;
  }
  return lb;
}
template <class A>
void read(vector<A>& v);
template <class A, size_t S>
void read(array<A, S>& a);
template <class T>
void read(T& x) {
  cin >> x;
}
void read(double& d) {
  string t;
  read(t);
  d = stod(t);
}
void read(long double& d) {
  string t;
  read(t);
  d = stold(t);
}
template <class H, class... T>
void read(H& h, T&... t) {
  read(h);
  read(t...);
}
template <class A>
void read(vector<A>& x) {
  for (auto& a : x) read(a);
}
template <class A, size_t S>
void read(array<A, S>& x) {
  for (auto& a : x) read(a);
}
template <typename T>
inline T max(const T& a, const T& b, const T& c) {
  return std::max(std::max(a, b), c);
}
template <typename T>
inline T max(const T& a, const T& b, const T& c, const T& d) {
  return std::max(max(a, b, c), d);
}
template <typename T>
inline T max(const T& a, const T& b, const T& c, const T& d, const T& e) {
  return std::max(max(a, b, c, d), e);
}
template <typename T>
inline T max(const T& a, const T& b, const T& c, const T& d, const T& e,
             const T& f) {
  return std::max(max(a, b, c, d, e), f);
}
template <typename T>
inline T max(const T& a, const T& b, const T& c, const T& d, const T& e,
             const T& f, const T& g) {
  return std::max(max(a, b, c, d, e, f), g);
}
template <typename T>
inline T max(const T& a, const T& b, const T& c, const T& d, const T& e,
             const T& f, const T& g, const T& h) {
  return std::max(max(a, b, c, d, e, f, g), h);
}
template <typename T>
inline T max(const T& a, const T& b, const T& c, const T& d, const T& e,
             const T& f, const T& g, const T& h, const T& i) {
  return std::max(max(a, b, c, d, e, f, g, h), i);
}
template <typename T>
inline T max(const T& a, const T& b, const T& c, const T& d, const T& e,
             const T& f, const T& g, const T& h, const T& i, const T& j) {
  return std::max(max(a, b, c, d, e, f, g, h, i), j);
}
template <typename T>
inline T min(const T& a, const T& b, const T& c) {
  return std::min(std::min(a, b), c);
}
template <typename T>
inline T min(const T& a, const T& b, const T& c, const T& d) {
  return std::min(min(a, b, c), d);
}
template <typename T>
inline T min(const T& a, const T& b, const T& c, const T& d, const T& e) {
  return std::min(min(a, b, c, d), e);
}
template <typename T>
inline T min(const T& a, const T& b, const T& c, const T& d, const T& e,
             const T& f) {
  return std::min(min(a, b, c, d, e), f);
}
template <typename T>
inline T min(const T& a, const T& b, const T& c, const T& d, const T& e,
             const T& f, const T& g) {
  return std::min(min(a, b, c, d, e, f), g);
}
template <typename T>
inline T min(const T& a, const T& b, const T& c, const T& d, const T& e,
             const T& f, const T& g, const T& h) {
  return std::min(min(a, b, c, d, e, f, g), h);
}
template <typename T>
inline T min(const T& a, const T& b, const T& c, const T& d, const T& e,
             const T& f, const T& g, const T& h, const T& i) {
  return std::min(min(a, b, c, d, e, f, g, h), i);
}
template <typename T>
inline T min(const T& a, const T& b, const T& c, const T& d, const T& e,
             const T& f, const T& g, const T& h, const T& i, const T& j) {
  return std::min(min(a, b, c, d, e, f, g, h, i), j);
}
int sumof(long long n) {
  int ans = 0;
  while (n > 0) {
    int digit = n % 10;
    ans += digit;
    n /= 10;
  }
  return ans;
}
int sumof(string s) {
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (isdigit(s[i])) {
      ans += (int)s[i] - '0';
    }
  }
  return ans;
}
int sumof(int h) {
  int ans = 0;
  while (h > 0) {
    int digit = h % 10;
    ans += digit;
    h /= 10;
  }
  return ans;
}
string to_string(char c) { return string(1, c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return string(s); }
string to_string(string s) { return s; }
string to_string(vector<bool> v) {
  string res;
  for (int i = (0); (1) > 0 ? i < ((int)(v).size()) : i > ((int)(v).size());
       i += (1))
    res += char('0' + v[i]);
  return res;
}
template <size_t S>
string to_string(bitset<S> b) {
  string res;
  for (int i = (0); (1) > 0 ? i < (S) : i > (S); i += (1))
    res += char('0' + b[i]);
  return res;
}
template <class T>
string to_string(T v) {
  bool f = 1;
  string res;
  for (auto& x : v) {
    if (!f) res += ' ';
    f = 0;
    res += to_string(x);
  }
  return res;
}
template <class A>
void write(A x) {
  cout << to_string(x);
}
template <class H, class... T>
void write(const H& h, const T&... t) {
  write(h);
  write(t...);
}
void print() { write("\n"); }
template <class H, class... T>
void print(const H& h, const T&... t) {
  write(h);
  if (sizeof...(t)) write(' ');
  print(t...);
}
void DBG() { cerr << "]" << endl; }
template <class H, class... T>
void DBG(H h, T... t) {
  cerr << to_string(h);
  if (sizeof...(t)) cerr << ", ";
  DBG(t...);
}
template <class T>
void offset(long long o, T& x) {
  x += o;
}
template <class T>
void offset(long long o, vector<T>& x) {
  for (auto& a : x) offset(o, a);
}
template <class T, size_t S>
void offset(long long o, array<T, S>& x) {
  for (auto& a : x) offset(o, a);
}
mt19937 mt_rng(chrono::steady_clock::now().time_since_epoch().count());
long long randint(long long a, long long b) {
  return uniform_int_distribution<long long>(a, b)(mt_rng);
}
template <class T, class U>
void vti(vector<T>& v, U x, size_t n) {
  v = vector<T>(n, x);
}
template <class T, class U>
void vti(vector<T>& v, U x, size_t n, size_t m...) {
  v = vector<T>(n);
  for (auto& a : v) vti(a, x, m);
}
const int d4i[4] = {-1, 0, 1, 0}, d4j[4] = {0, 1, 0, -1};
const int d8i[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
          d8j[8] = {0, 1, 1, 1, 0, -1, -1, -1};
void Solve() {
  int a;
  cin >> a;
  unordered_map<string, string> mapka;
  while (a--) {
    string x, y;
    int ans = 0;
    cin >> x >> y;
    for (auto& t : mapka) {
      if (t.second == x) {
        t.second = y;
        ans++;
        break;
      }
    }
    if (ans == 0) {
      mapka[x] = y;
    }
  }
  print(mapka.size());
  for (auto& t : mapka) {
    print(t.first, t.second);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int i = 0; i < t; i++) {
    Solve();
  }
}