#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> names;
  map<string, int> cont;
  int n;
  string s1, s2;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    names[s1] = s2;
    cont[s1] += 0;
    cont[s2]++;
    names[s2] = "-1";
  }
  int c = 0;
  for (auto it : cont) {
    c += (it.second == 0);
  }
  cout << c << endl;
  for (auto it : cont) {
    if (it.second == 0) {
      cout << it.first << " ";
      s1 = it.first;
      while (names[s1] != "-1") {
        s1 = names[s1];
      }
      cout << s1 << endl;
    }
  }
  return 0;
}
