#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string oldh, newh;
  map<string, string> used_map, new_map;
  while (n--) {
    cin >> oldh >> newh;
    if (used_map.count(oldh) == 0) {
      used_map[oldh] = oldh;
      used_map[newh] = oldh;
      new_map[oldh] = newh;
    } else {
      used_map[newh] = used_map[oldh];
      new_map[used_map[oldh]] = newh;
    }
  }
  cout << new_map.size() << endl;
  map<string, string>::iterator it;
  for (it = new_map.begin(); it != new_map.end(); it++) {
    cout << it->first << " " << it->second << endl;
  }
  return 0;
}
