#include <bits/stdc++.h>
using namespace std;
map<string, string> a, b;
string x[100005], y[100005];
vector<pair<string, string> > ans;
map<string, bool> v;
int main() {
  ios::sync_with_stdio(0);
  int n, i = 0;
  cin >> n;
  while (i < n) {
    cin >> x[i] >> y[i];
    a[x[i]] = y[i];
    b[y[i]] = x[i];
    i++;
  }
  for (int i = n - 1; i >= 0; i--) {
    if (v[y[i]] == 0) {
      v[y[i]] = 1;
      string old = x[i];
      while (b.find(old) != b.end()) {
        v[old] = 1;
        old = b[old];
        v[old] = 1;
      }
      v[old] = 1;
      ans.push_back({old, y[i]});
    }
  }
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first << " " << ans[i].second << "\n";
  }
}
