#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  map<string, string> names, rev_names;
  set<string> uniq;
  while (n--) {
    string a, b;
    cin >> a >> b;
    names.insert(pair<string, string>(a, b));
    rev_names.insert(pair<string, string>(b, a));
    if (rev_names.find(a) == rev_names.end()) {
      uniq.insert(a);
    }
  }
  cout << uniq.size() << "\n";
  for (auto i = uniq.begin(); i != uniq.end(); i++) {
    auto j = names.find(*i);
    cout << j->first << " ";
    map<string, string>::iterator k;
    while (true) {
      k = names.find(j->second);
      if (k != names.end()) {
        j = k;
      } else {
        break;
      }
    }
    cout << j->second << "\n";
  }
  return 0;
}
