#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, i;
  cin >> q;
  string s1, s2;
  map<string, string> m;
  map<string, string>::iterator it;
  for (i = 0; i < q; i++) {
    cin >> s1 >> s2;
    m[s1] = s2;
    for (it = m.begin(); it != m.end(); ++it) {
      if (s1 == it->second) {
        it->second = s2;
        m.erase(s1);
      }
    }
  }
  cout << m.size() << endl;
  for (it = m.begin(); it != m.end(); ++it)
    cout << it->first << " " << it->second << endl;
  return 0;
}
