#include <bits/stdc++.h>
using namespace std;
map<string, string> base;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string k, v;
    cin >> k >> v;
    base[v] = k;
    if (!base[k].empty()) {
      base[v] = base[k];
    }
    base.erase(k);
  }
  cout << base.size() << endl;
  for (auto &kvp : base) {
    cout << kvp.second << ' ' << kvp.first << endl;
  }
  return 0;
}
