#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, a, b;
  cin >> q;
  string s, t;
  set<string> names;
  set<string> uni;
  map<string, int> kol;
  map<string, string> ch;
  for (int i = 0; i < q; ++i) {
    cin >> s >> t;
    a = names.size();
    names.insert(s);
    b = names.size();
    if (a != b) {
      uni.insert(s);
    }
    ++kol[s];
    ch[s] = t;
    names.insert(t);
  }
  cout << uni.size() << '\n';
  for (auto c : uni) {
    cout << c << " ";
    while (kol[c] > 0) {
      c = ch[c];
    }
    cout << c << '\n';
  }
  return 0;
}
