#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, string> change;
  string old_name, new_name;
  map<string, string>::iterator it;
  for (int i = 0; i < n; i++) {
    cin >> old_name >> new_name;
    if ((it = change.find(old_name)) != change.end()) {
      old_name = (*it).second;
      change.erase(it);
    }
    change[new_name] = old_name;
  }
  cout << change.size() << endl;
  for (it = change.begin(); it != change.end(); ++it)
    cout << (*it).second << ' ' << (*it).first << endl;
}
