#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<string> fn;
  long long q, i, n;
  string s1, s2;
  map<string, string> hash;
  cin >> q;
  bool newone;
  while (q--) {
    cin >> s1 >> s2;
    newone = true;
    for (i = 0; i < fn.size(); i++) {
      if (hash[fn[i]] == s1) {
        newone = false;
        break;
      }
    }
    if (newone) {
      fn.push_back(s1);
      hash[s1] = s2;
    } else {
      hash[fn[i]] = s2;
    }
  }
  cout << fn.size() << "\n";
  for (i = 0; i < fn.size(); i++) cout << fn[i] << " " << hash[fn[i]] << "\n";
  return 0;
}
