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