#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<deque<string>> data;
  for (int i = 0; i < n; ++i) {
    string u, v;
    cin >> u >> v;
    bool added = false;
    for (int j = 0; j < data.size(); ++j) {
      if (data[j].back() == u) {
        data[j].push_back(v);
        added = true;
        break;
      }
    }
    if (!added) {
      deque<string> adding{u, v};
      data.push_back(adding);
    }
  }
  cout << data.size() << endl;
  for (int i = 0; i < data.size(); ++i) {
    cout << data[i].front() << " " << data[i].back() << endl;
  }
  return 0;
}
