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;
bool CMP(int a, int b) { return a > b; }
long long int p = 1e9 + 7;
long long int power2(long long int n) {
  long long int res = 1;
  for (long long int i = 1; i <= n; i++) res *= 2;
  return res;
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  if (x == 0) return 0;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int cnt1 = 0, u, cnt = 0, n;
vector<vector<long long int>> adj1(200010);
vector<pair<long long int, long long int>> adj[200010];
vector<long long int> wt(200010);
long long int visi[310068], vis[300100], last1[10000];
vector<long long int> viso;
bool ok = false;
long long int m, ans = 0;
long long int dp[200010];
bool mycompare(pair<long long int, string> p, pair<long long int, string> t) {
  if (p.first == t.first && p.second < t.second)
    return true;
  else if (p.first == t.first && p.second > t.second)
    return false;
  else if (p.first < t.first)
    return false;
  else if (p.first > t.first)
    return true;
  else
    return false;
}
long long int maxi = 1e7;
set<long long int> w;
pair<long long int, long long int> rotate(long long int x, long long int y,
                                          long long int a, long long int b,
                                          long long int t) {
  long long int i;
  for (i = 0; i < t; i++) {
    long long int p = a + b - y, q = x + b - a;
    x = p, y = q;
  }
  pair<long long int, long long int> P = make_pair(x, y);
  return P;
}
long long int dist(long long int x1, long long int y1, long long int x2,
                   long long int y2) {
  long long int d = (x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1);
  return d;
}
bool check(long long int x1, long long int y1, long long int x2,
           long long int y2, long long int x3, long long int y3,
           long long int x4, long long int y4) {
  long long int d2 = dist(x1, y1, x2, y2);
  long long int d3 = dist(x1, y1, x3, y3);
  long long int d4 = dist(x1, y1, x4, y4);
  if (d2 == 0 || d3 == 0 || d4 == 0) return false;
  if (d2 == d3 && d4 == 2 * d2 &&
      2 * dist(x2, y2, x4, y4) == dist(x2, y2, x3, y3))
    return true;
  if (d3 == d4 && d2 == 2 * d3 &&
      2 * dist(x2, y2, x3, y3) == dist(x3, y3, x4, y4))
    return true;
  if (d2 == d4 && d3 == 2 * d2 &&
      2 * dist(x2, y2, x3, y3) == dist(x2, y2, x4, y4))
    return true;
  return false;
}
long long int A[20010];
class SegmentTree {
 public:
  vector<long long int> A;
  vector<long long int> tree;
  long long int n, d;
  SegmentTree(vector<long long int> &inp, long long int depth) {
    A = inp;
    d = depth;
    n = A.size();
    tree.resize(4 * n);
    build(1, 0, n - 1, d);
  }
  void build(long long int node, long long int start, long long int end,
             long long int depth) {
    if (start == end)
      tree[node] = A[start];
    else {
      long long int mid = (start + end) / 2;
      build(2 * node, start, mid, depth - 1);
      build(2 * node + 1, mid + 1, end, depth - 1);
      if (depth % 2 == 1)
        tree[node] = tree[2 * node] | tree[2 * node + 1];
      else
        tree[node] = tree[2 * node] ^ tree[2 * node + 1];
    }
  }
  void update(long long int node, long long int start, long long int end,
              long long int idx, long long int depth) {
    if (start == end) {
      tree[node] = A[start];
    } else {
      long long int mid = (start + end) / 2;
      if (start <= idx && idx <= mid)
        update(2 * node, start, mid, idx, depth - 1);
      else
        update(2 * node + 1, mid + 1, end, idx, depth - 1);
      if (depth % 2 == 1)
        tree[node] = tree[2 * node] | tree[2 * node + 1];
      else
        tree[node] = tree[2 * node] ^ tree[2 * node + 1];
    }
  }
  long long int update(long long int index, long long int value) {
    A[index] = value;
    update(1, 0, n - 1, index, d);
    return tree[1];
  }
};
priority_queue<pair<long long int, long long int>,
               vector<pair<long long int, long long int>>,
               greater<pair<long long int, long long int>>>
    pq;
void dj(long long int s) {
  pair<long long int, long long int> pi;
  for (long long int i = 0; i < adj[s].size(); i++) {
    if (vis[adj[s][i].first] > vis[s] + adj[s][i].second) {
      vis[adj[s][i].first] = vis[s] + adj[s][i].second;
      visi[adj[s][i].first] = s;
      pq.push(make_pair(vis[adj[s][i].first], adj[s][i].first));
    }
  }
  if (pq.empty()) return;
  pi = pq.top();
  pq.pop();
  dj(pi.second);
}
void path(long long int x) {
  if (x == 0) return;
  path(visi[x]);
  cout << x << " ";
}
bool note(pair<string, long long int> p, pair<string, long long int> s) {
  if (p.second < s.second)
    return false;
  else if (p.second > s.second)
    return true;
  else if (p.second == s.second && p.first < s.first)
    return true;
  else
    return false;
}
bool isPowerOfTwo(long long int n) {
  if (n == 0) return false;
  return (ceil(log2(n)) == floor(log2(n)));
}
vector<string> adjs(200010);
int main() {
  long long int n;
  cin >> n;
  long long int i;
  map<string, string> mp;
  set<string> st;
  for (i = 0; i < n; i++) {
    string s, t;
    cin >> s >> t;
    mp[s] = t;
    st.insert(t);
  }
  vector<pair<string, string>> ans;
  for (map<string, string>::iterator it = mp.begin(); it != mp.end(); it++) {
    if (st.count(it->first)) continue;
    string cur = it->first;
    while (mp.count(cur)) cur = mp[cur];
    ans.push_back(make_pair(it->first, cur));
  }
  cout << ans.size() << endl;
  for (i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
}
