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;
long long const N = 2e5 + 5, M = 5e5 + 5, OO = 1e18;
long long mx(long long a, long long b) {
  if (a <= b) {
    return b;
  } else {
    return a;
  }
}
long long mn(long long a, long long b) {
  if (a <= b) {
    return a;
  } else {
    return b;
  }
}
long n, m, u, v, comp, cyc;
vector<vector<long>> adj(N);
vector<long> ans, path;
long dis[N], par[N], sz[M];
bool isBi = 1;
bool vis[N], col[N], stc[N];
queue<long> q;
vector<pair<int, int>> ansp, pathp;
map<pair<int, int>, pair<int, int>> parp;
map<pair<int, int>, int> distp, colp, stcp;
queue<pair<int, int>> qp;
map<pair<int, int>, bool> visp;
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
int dest_x, dest_y;
char grid[1000][1000];
set<int> row;
set<int> column;
void DFSp(int x, int y, int n, int m) {
  if (x == dest_x && y == dest_y) return;
  if (grid[x][y] != '.' && x < n && y < m && x >= 0 && y >= 0 &&
      !visp[{x, y}]) {
    visp[{x, y}] = true;
    if (y - 1 >= 0 && grid[x][y - 1] == '*') {
      row.insert(x);
    }
    if (y + 1 < m && grid[x][y + 1] == '*') {
      row.insert(x);
    }
    if (x - 1 >= 0 && grid[x - 1][y] == '*') {
      column.insert(y);
    }
    if (x + 1 < n && grid[x + 1][y] == '*') {
      column.insert(y);
    }
    ansp.push_back({x, y});
    DFSp(x + 1, y, n, m);
    DFSp(x, y + 1, n, m);
    DFSp(x - 1, y, n, m);
    DFSp(x, y - 1, n, m);
  }
}
void BFSp(pair<int, int> src, pair<int, int> dest, int n, int m) {
  qp.push(src);
  visp[src] = 1;
  parp[src] = {-1, -1};
  colp[src] = 1;
  while (!qp.empty()) {
    pair<int, int> pr = qp.front();
    qp.pop();
    int i = pr.first;
    int j = pr.second;
    if (i < 0 || i >= n || j < 0 || j >= m) continue;
    pair<int, int> v[] = {{i + 1, j}, {i, j + 1}, {i, j - 1}, {i - 1, j}};
    for (pair<int, int> u : v)
      if (!visp[u]) {
        visp[u] = true;
        distp[u] = distp[pr] + 1;
        qp.push(u);
        parp[u] = pr;
        colp[u] = !colp[pr];
      }
  }
  pathp.push_back(dest);
  pair<int, int> node = dest;
  do {
    node = parp[node];
    pathp.push_back(node);
  } while (node != src);
  reverse(pathp.begin(), pathp.end());
}
void BFS(int s, int dest) {
  q.push(s);
  vis[s] = true;
  par[s] = -1;
  col[s] = 1;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (auto u : adj[v]) {
      if (!vis[u]) {
        cout << "current " << u << endl;
        vis[u] = true;
        q.push(u);
        dis[u] = dis[v] + 1;
        par[u] = v;
        col[u] = !col[v];
      }
    }
  }
  path.push_back(dest);
  int node = dest;
  do {
    node = par[node];
    path.push_back(node);
  } while (node != s);
  reverse(path.begin(), path.end());
}
int h = 0;
long long DFS(int u, int p) {
  vis[u] = 1;
  col[u] = 1;
  stc[u] = 1;
  for (auto v : adj[u]) {
    if (v != p) {
      if (stc[v]) cyc++;
      if (!vis[v]) {
        col[v] = !col[u];
        h = mx(h, 1 + DFS(v, u));
      } else if (col[v] == col[u])
        isBi = 0;
    }
  }
  stc[u] = 0;
  ans.push_back(u);
  return h;
}
priority_queue<pair<int, int>> pq;
vector<long long> dist(N, OO);
vector<vector<pair<long, long>>> adjedges(N);
void dijkstra(long src, long dest) {
  dist[src] = 0;
  pq.push({0, src});
  while (!pq.empty()) {
    long a = pq.top().second;
    pq.pop();
    if (vis[a]) continue;
    vis[a] = true;
    for (auto u : adjedges[a]) {
      long b = u.first, w = u.second;
      if (dist[a] + (w % OO) < dist[b]) {
        dist[b] = dist[a] + w;
        pq.push({-dist[b], b});
        par[b] = a;
      }
    }
  }
  if (dist[dest] != OO) {
    path.push_back(dest);
    int node = dest;
    do {
      node = par[node];
      path.push_back(node);
    } while (node != src);
    reverse(path.begin(), path.end());
  }
}
int findParent(int u) {
  if (par[u] == u) return u;
  return par[u] = findParent(par[u]);
}
void join(int a, int b) {
  a = findParent(a);
  b = findParent(b);
  if (a != b) {
    par[b] = a;
    sz[a] += sz[b];
  }
}
map<string, vector<string>> mstr;
map<string, bool> mvis;
vector<string> mans;
void dfs(string u) {
  mvis[u] = 1;
  for (auto v : mstr[u]) {
    if (!mvis[v]) dfs(v);
  }
  mans.push_back(u);
}
int main() {
  int n;
  cin >> n;
  set<string> s1;
  set<string> s2;
  for (int i = 0; i < n; i++) {
    string str1, str2;
    cin >> str1 >> str2;
    mstr[str1].push_back(str2);
    if (s2.find(str1) == s2.end()) {
      s1.insert(str1);
    }
    s2.insert(str2);
  }
  for (auto x : s1) {
    if (!mvis[x]) {
      comp++;
      dfs(x);
    }
  }
  for (auto x : s1) mvis[x] = 0;
  for (auto x : s2) mvis[x] = 0;
  cout << comp << endl;
  for (auto x : s1) {
    if (!mvis[x]) {
      dfs(x);
      cout << mans[mans.size() - 1] << " " << mans[0] << endl;
      mans.resize(0);
    }
  }
}