#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  map<string, int> mp_ind;
  vector<pair<string, string> > vec;
  string a = " ", b = " ";
  pair<string, string> p;
  vec.push_back({"", ""});
  while (t--) {
    cin >> a >> b;
    if (!mp_ind[a]) {
      int len = vec.size();
      mp_ind[a] = mp_ind[b] = len;
      vec.push_back({a, b});
    } else {
      int len = mp_ind[a];
      mp_ind[b] = len;
      vec[len].second = b;
    }
  }
  cout << vec.size() - 1 << endl;
  for (int i = 1; i < vec.size(); i++)
    cout << vec[i].first << " " << vec[i].second << endl;
  return 0;
}
