#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<pair<string, string> > handles;
  int q, g, i, found;
  pair<string, string> temp;
  cin >> q;
  string from, to;
  for (i = 0; i < q; i++) {
    found = 0;
    cin >> from >> to;
    for (g = 0; g < handles.size(); g++) {
      if (handles.at(g).second == from) {
        found = 1;
        handles.at(g).second = to;
        break;
      }
    }
    if (found == 0) {
      temp.first = from;
      temp.second = to;
      handles.push_back(temp);
    }
  }
  cout << handles.size() << endl;
  for (i = 0; i < handles.size(); i++) {
    cout << handles.at(i).first << " " << handles.at(i).second << endl;
  }
  return 0;
}
