#include <bits/stdc++.h>
using namespace std;
int TN = 1;
void sol() {
  int q;
  cin >> q;
  map<string, string> nms;
  map<string, string> cur;
  vector<string> ans;
  string ld, nw;
  for (int i = 0; i < q; ++i) {
    cin >> ld >> nw;
    if (!cur.count(ld)) {
      ans.push_back(ld);
      nms[ld] = nw;
      cur[nw] = ld;
    } else {
      nms[cur[ld]] = nw;
      cur[nw] = cur[ld];
    }
  }
  cout << ans.size() << '\n';
  for (int i = 0; i < (int)ans.size(); ++i) {
    cout << ans[i] << ' ' << nms[ans[i]] << '\n';
  }
}
int main() {
  while (TN--) {
    sol();
  }
  return 0;
}
