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