#include <bits/stdc++.h>
using namespace std;
bool was[2000];
string s1[2000], s2[2000], ans1[2000], ans2[2000];
bool go(string s3, string s4) {
  if (s3.size() != s4.size()) {
    return false;
  }
  for (int j = 0; j < s4.size(); j++) {
    if (s3[j] != s4[j]) {
      return false;
    }
  }
  return true;
}
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s1[i] >> s2[i];
  }
  int kol = 0;
  for (int i = 1; i <= n; i++) {
    if (!was[i]) {
      string z = s2[i];
      bool ok = true;
      int t = i;
      while (ok) {
        bool ok1 = false;
        for (int j = t + 1; j <= n; j++) {
          if (go(z, s1[j])) {
            z = s2[j];
            was[j] = true;
            t = j;
            ok1 = true;
          }
        }
        if (!ok1) {
          break;
        }
      }
      ans1[++kol] = s1[i];
      ans2[kol] = z;
    }
  }
  cout << kol << endl;
  for (int j = 1; j <= kol; j++) {
    cout << ans1[j] << " " << ans2[j] << endl;
  }
  return 0;
}
