#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string _old, _new;
  set<string> notbegin;
  map<string, string> changes;
  for (int i = 0; i < n; i++) {
    cin >> _old >> _new;
    notbegin.insert(_new);
    changes[_old] = _new;
  }
  vector<pair<string, string> > ans;
  for (auto x : changes) {
    if (notbegin.count(x.first)) {
      continue;
    }
    string cur = x.first;
    while (changes.count(cur)) {
      cur = changes[cur];
    }
    ans.push_back({x.first, cur});
  }
  cout << ans.size() << endl;
  for (auto x : ans) {
    cout << x.first << " " << x.second << endl;
  }
  return 0;
}
