#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> dsu;
  int q;
  cin >> q;
  while (q--) {
    string x, y;
    cin >> x >> y;
    dsu[y] = (dsu[x] != "" ? dsu[x] : x);
    dsu.erase(x);
  }
  cout << dsu.size() << endl;
  for (auto i : dsu) {
    cout << i.second << " " << i.first << endl;
  }
  return 0;
}
