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;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first == b.first)
    return a.second > b.second;
  else
    return a.first < b.first;
}
long long fact(long long n) {
  if (n == 1 || n == 0)
    return 1;
  else
    return n * fact(n - 1);
}
bool compp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.first > b.first;
}
vector<int> prime(20012, 1);
void preprocessing() {
  prime[0] = 0, prime[1] = 0;
  for (int i = 2; i * i <= 20012; i++) {
    if (prime[i] == 1) {
      for (int j = i * i; j <= 20012; j += i) {
        prime[j] = 0;
      }
    }
  }
  for (int i = 0; i < prime.size(); i++)
    if (prime[i] != 0) prime[i] = i;
  sort(prime.begin(), prime.end());
  vector<int>::iterator r;
  for (auto i = prime.begin(); i != prime.end(); ++i) {
    if (*(i + 1) != 0) {
      r = i + 1;
      break;
    }
  }
  prime.erase(prime.begin(), r);
}
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.first != b.first)
    return a.first > b.first;
  else
    return a.second < b.second;
}
string bin(long long n) {
  string ans;
  while (n) {
    ans.append(to_string(n % 2));
    n /= 2;
  }
  reverse(ans.begin(), ans.end());
  return ans;
}
long long gcd(long long a, long long b) {
  if (a % b == 0)
    return b;
  else
    return (gcd(b, a % b));
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
bool perf(string s) {
  int cnt = 0;
  for (int i = s.size() - 1; i >= s.size() - 7; i--)
    if (s[i] == '0') cnt++;
  if (cnt == 6)
    return true;
  else
    return false;
}
int binary(vector<int> v, int k) {
  int lo = 0, hi = v.size() - 1;
  while (lo <= hi) {
    int mid = lo + (hi - lo) / 2;
    if (v[mid] == k)
      return mid;
    else if (v[mid] > k)
      hi = mid - 1;
    else
      lo = mid + 1;
  }
  return -1;
}
void ready() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
}
void inp() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
int main() {
  ready();
  map<string, string> mm;
  int q;
  cin >> q;
  vector<pair<pair<string, bool>, bool>> ol, ne;
  while (q--) {
    string s1, s2;
    cin >> s1 >> s2;
    ol.push_back(make_pair(make_pair(s1, true), true));
    ne.push_back(make_pair(make_pair(s2, true), true));
  }
  q = ol.size();
  for (int i = 1; i < q; i++) {
    for (int j = i - 1; j >= 0; j--) {
      if (ne[i].first.first == ne[j].first.first ||
          ne[i].first.first == ol[j].first.first)
        ne[i].first.second = false, ol[i].first.second = false;
    }
  }
  int cnt = 0;
  for (int i = 0; i < q; i++) {
    if (ol[i].first.second) {
      for (int j = 0; j < q; j++) {
        if (ol[i].first.first == ne[j].first.first && ne[j].first.second) {
          ol[i].second = false;
          break;
        }
      }
      if (ol[i].second) cnt++;
    }
  }
  cout << cnt << endl;
  for (int i = 0; i < q - 1; i++) {
    if (ol[i].second && ol[i].first.second) {
      mm[ol[i].first.first] = ne[i].first.first;
      for (int j = i + 1; j < q; j++) {
        if (ol[j].first.first == mm[ol[i].first.first] && ol[j].first.second)
          mm[ol[i].first.first] = ne[j].first.first;
      }
      cout << ol[i].first.first << " " << mm[ol[i].first.first] << endl;
    }
  }
  if (ol[q - 1].first.second && ol[q - 1].second)
    cout << ol[q - 1].first.first << " " << ne[q - 1].first.first;
  return 0;
}