#include <bits/stdc++.h>
using namespace std;
vector<pair<string, string> > v;
int main() {
  long long q;
  cin >> q;
  while (q--) {
    string x, y;
    cin >> x >> y;
    if (v.empty()) {
      v.push_back({x, y});
    } else {
      long long done = false;
      for (int i = 0; i < v.size(); i++) {
        if (v[i].second == x) {
          v[i].second = y;
          done = true;
          break;
        }
      }
      if (!done) {
        v.push_back({x, y});
      }
    }
  }
  sort(v.begin(), v.end());
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i].first << ' ' << v[i].second << endl;
  }
  return 0;
}
