#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> m;
  long long int t;
  cin >> t;
  while (t--) {
    string s1, s2;
    cin >> s1 >> s2;
    m[s1] = s2;
    m[s2] = "-1";
  }
  map<string, string> l;
  map<string, bool> tr;
  for (map<string, string>::iterator it = m.begin(); it != m.end(); ++it) {
    string k = it->first;
    if (it->second != "-1" && tr[k] != true) {
      while (m[k] != "-1") {
        tr[k] = true;
        k = m[k];
      }
      l[k] = it->first;
    }
  }
  cout << l.size() << endl;
  for (map<string, string>::iterator it = l.begin(); it != l.end(); ++it) {
    cout << it->second << " " << it->first << endl;
  }
  return 0;
}
