#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, string> res;
  map<string, int> cnt;
  for (int i = 0; i < n; i++) {
    string old, new_;
    cin >> old >> new_;
    cnt[new_]++;
    if (!cnt[old]) {
      res[old] = new_;
      cnt[old]++;
    } else {
      for (auto x : res) {
        if (x.second == old) res[x.first] = new_;
      }
    }
  }
  cout << res.size() << endl;
  for (auto x : res) {
    cout << x.first << " " << x.second << endl;
  }
}
