#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, string> m;
  map<string, string> m2;
  string a, b;
  vector<string> v;
  for (long long i = (0); i < (n); i++) {
    cin >> a >> b;
    m[a] = b;
    m2[b] = a;
    v.push_back(a);
  }
  for (long long i = (0); i < (n); i++) {
    while (m[m[v[i]]] != "") {
      m[v[i]] = m[m[v[i]]];
    }
  }
  int sum = 0;
  for (long long i = (0); i < (v.size()); i++) {
    if (m2[v[i]] == "") {
      sum++;
    }
  }
  cout << sum << endl;
  for (long long i = (0); i < (v.size()); i++) {
    if (m2[v[i]] == "") {
      cout << v[i] << " " << m[v[i]] << endl;
    }
  }
}
