#include <bits/stdc++.h>
using namespace std;
struct Name {
  string oldU, newU;
} name[1010];
int main() {
  int q;
  cin >> q;
  for (int t = 0; t < q; t++) {
    cin >> name[t].oldU >> name[t].newU;
  }
  int cnt = 0;
  for (int i = 0; i < q; i++) {
    for (int j = i + 1; j < q; j++) {
      if (name[i].oldU != "NULL" || name[i].newU != "NULL")
        if (name[i].newU == name[j].oldU) {
          name[i].newU = name[j].newU;
          name[j].oldU = name[j].newU = "NULL";
          cnt++;
        }
    }
  }
  cout << q - cnt << endl;
  for (int i = 0; i < q; i++) {
    if (name[i].oldU != "NULL" || name[i].newU != "NULL")
      cout << name[i].oldU << " " << name[i].newU << endl;
  }
  return 0;
}
