#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, top = 0;
  vector<string> name[1000];
  cin >> q;
  while (q--) {
    string os, ns;
    cin >> os >> ns;
    for (int i = 0; i <= top; i++) {
      if (name[i].size() == 0) {
        name[i].push_back(os);
        name[i].push_back(ns);
        top++;
        break;
      } else if (name[i].back() == os) {
        name[i].push_back(ns);
        break;
      }
    }
  }
  cout << top << endl;
  for (int i = 0; i < top; i++) {
    cout << name[i].front() << " " << name[i].back() << endl;
  }
  return 0;
}
