#include <bits/stdc++.h>
using namespace std;
map<string, string> R;
map<string, int> M;
int main() {
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string tmp1, tmp2;
    cin >> tmp1 >> tmp2;
    R[tmp1] = tmp2;
    M[tmp1] += 1;
    M[tmp2] += 2;
  }
  cout << M.size() - R.size() << endl;
  for (map<string, int>::iterator i = M.begin(); i != M.end(); i++) {
    if (i->second == 1) {
      cout << i->first << ' ';
      string S = i->first;
      while (M[S] != 2) {
        S = R[S];
      }
      cout << S << endl;
    }
  }
}
