#include <bits/stdc++.h>
using namespace std;
map<string, string> transfer;
set<string> to_points;
;
int q;
int main() {
  cin >> q;
  for (int i = 0; i < q; i++) {
    string old_handle, new_handle;
    cin >> old_handle >> new_handle;
    to_points.insert(new_handle);
    transfer[old_handle] = new_handle;
  }
  int c = 0;
  for (map<string, string>::iterator iter = transfer.begin();
       iter != transfer.end(); iter++) {
    if (to_points.find(iter->first) == to_points.end()) {
      c++;
    }
  }
  cout << c << endl;
  for (map<string, string>::iterator iter = transfer.begin();
       iter != transfer.end(); iter++) {
    if (to_points.find(iter->first) == to_points.end()) {
      string new_handle = transfer[iter->first];
      while (transfer.find(new_handle) != transfer.end()) {
        new_handle = transfer[new_handle];
      }
      cout << iter->first << " " << new_handle << endl;
    }
  }
  return 0;
}
