#include <bits/stdc++.h>
using namespace std;
int n;
string od, nw;
int par[2005];
bool mark[2005];
map<string, int> m;
string str[2005];
int id;
vector<pair<int, int> > v;
int findPar(int x) { return par[x] == x ? x : par[x] = findPar(par[x]); }
int main() {
  id = 0;
  cin >> n;
  for (int i = 0; i < 2005; i++) {
    par[i] = i;
    str[i] = "";
  }
  for (int i = 0; i < n; i++) {
    cin >> od >> nw;
    if (m.find(od) == m.end()) {
      m[od] = ++id;
      str[id] = od;
    }
    if (m.find(nw) == m.end()) {
      m[nw] = ++id;
      str[id] = nw;
    }
    int a = findPar(m[od]);
    par[m[nw]] = a;
  }
  for (int i = 2002; i >= 0; i--) {
    int a = findPar(i);
    if (a != i && mark[a] == 0) {
      mark[a] = 1;
      v.push_back(make_pair(a, i));
    }
  }
  printf("%d\n", v.size());
  for (int i = 0; i < v.size(); i++) {
    cout << str[v[i].first] << " " << str[v[i].second] << "\n";
  }
}
