#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  map<string, string> cont;
  set<string> ans;
  vector<pair<string, string>> sol;
  while (t--) {
    string a, b;
    cin >> a >> b;
    cont[a] = b;
    ans.insert(b);
  }
  for (auto i : cont) {
    if (ans.count(i.first)) {
      continue;
    }
    string temp = i.second;
    while (cont.count(temp)) {
      temp = cont[temp];
    }
    sol.push_back(make_pair(i.first, temp));
  }
  cout << sol.size() << "\n";
  for (auto i : sol) {
    cout << i.first << " " << i.second << "\n";
  }
  return 0;
}
