#include <bits/stdc++.h>
using namespace std;
map<string, string> M;
map<string, bool> K;
int main() {
  string so[1001], sn[1001];
  vector<string> v1, v2;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> so[i] >> sn[i];
    M[so[i]] = sn[i];
  }
  for (int i = 0; i < n; i++) {
    if (!K[so[i]]) {
      v1.push_back(so[i]);
      string c = so[i];
      K[so[i]] = true;
      while (1) {
        c = M[c];
        if (M[c].size() == 0) {
          v2.push_back(c);
          K[c] = true;
          break;
        }
        K[c] = true;
      }
    }
  }
  cout << v1.size() << endl;
  for (int i = 0; i < v1.size(); i++) cout << v1[i] << " " << v2[i] << endl;
}
