#include <bits/stdc++.h>
using namespace std;
struct handel {
  string old;
  string newh;
};
int main() {
  int q;
  cin >> q;
  handel* h = new handel[q];
  string old, newh;
  for (int i = 0; i < q; i++) {
    cin >> h[i].old;
    cin >> h[i].newh;
  }
  int num = 0;
  for (int i = 0; i < q; i++) {
    for (int j = 0; j < q; j++) {
      if (h[i].newh == h[j].old && h[j].old != "") {
        h[i].newh = h[j].newh;
        h[j].newh = "";
        h[j].old = "";
      }
    }
  }
  for (int i = 0; i < q; i++) {
    if (h[i].old != "") num++;
  }
  cout << num << endl;
  for (int i = 0; i < q; i++) {
    if (h[i].old != "") cout << h[i].old << " " << h[i].newh << endl;
  }
  return 0;
}
