#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<pair<string, string> > a;
  for (int i = 0; i < n; i++) {
    string k, v;
    cin >> k >> v;
    a.push_back(make_pair(k, v));
  }
  int mi = 0;
  map<string, bool> used;
  for (int i = 0; i < n; i++) {
    if (!used[a[i].first]) {
      for (int j = i + 1; j < n; j++) {
        if (a[j].first == a[i].second) {
          a[i].second = a[j].second;
          used[a[j].first] = true;
          mi++;
        }
      }
    }
  }
  cout << n - mi << endl;
  for (int i = 0; i < n; i++) {
    if (!used[a[i].first]) {
      cout << a[i].first << ' ' << a[i].second << endl;
    }
  }
}
