#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string a[1000], b[1000], x[1000], y[1000];
  bool v[1000];
  int k = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    v[i] = true;
  }
  for (int i = 0; i < n; i++) {
    if (v[i]) {
      v[i] = false;
      string c = a[i], d = b[i];
      for (int j = i + 1; j < n; j++) {
        if (a[j] == d and v[j]) {
          d = b[j];
          v[j] = false;
        }
      }
      x[k] = c;
      y[k] = d;
      k++;
    }
  }
  cout << k << endl;
  for (int i = 0; i < k; i++) {
    cout << x[i] << " " << y[i] << endl;
  }
  return 0;
}
