#include <bits/stdc++.h>
using namespace std;
vector<int> a, b;
map<string, string> d, all;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string a, b;
    cin >> a >> b;
    if (!all.count(b)) {
      all[a] = all[b] = 1;
      if (!d.count(a)) {
        d[b] = a;
      } else {
        d[b] = d[a];
        d.erase(a);
      }
    }
  }
  cout << d.size() << "\n";
  for (map<string, string>::iterator it = d.begin(); it != d.end(); it++) {
    cout << it->second << " " << it->first << "\n";
  }
  return 0;
}
