#include <bits/stdc++.h>
using namespace std;
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, string> x;
  vector<string> xx;
  string s[n], ss[n];
  for (int i = 0; i < n; i++) cin >> s[i] >> ss[i], x[s[i]] = ss[i];
  for (int i = 0; i < n; i++) {
    if (!x[s[i]].empty()) {
      string z = ss[i], zz = z;
      while (!x[z].empty()) z = x[z], x[zz].clear(), zz = z;
      xx.push_back(s[i]);
      xx.push_back(z);
    }
  }
  cout << xx.size() / 2 << endl;
  for (int i = 0; i < xx.size(); i += 2)
    cout << xx[i] << " " << xx[i + 1] << endl;
  return 0;
}
