#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> m1, ans;
  map<string, int> m2;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string a, b;
    cin >> a >> b;
    m1[a] = b;
    m2[b]++;
  }
  for (auto it : m1) {
    string c = it.first;
    if (m2[c]) {
      continue;
    } else {
      string c1 = c;
      while (m1[c1].size()) {
        c1 = m1[c1];
      }
      ans[c] = c1;
    }
  }
  cout << ans.size() << "\n";
  for (auto it : ans) {
    cout << it.first << " " << it.second << "\n";
  }
  return 0;
}
