#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int q, change = 0;
  cin >> q;
  cin.ignore();
  map<string, string> mp1;
  map<string, string> mp2;
  map<string, string>::iterator it;
  map<string, int> mark;
  while (q--) {
    string name1, name2;
    cin >> name1 >> name2;
    mark[name1]++;
    mark[name2]++;
    if (mark[name1] == 1 && name1 != name2) change++;
    if (mp2[name1] != "") {
      mp1[mp2[name1]] = name2;
      mp2[name2] = mp2[name1];
    } else if (mp1[name1] == "" && mp2[name2] == "") {
      mp1[name1] = name2;
      mp2[name2] = name1;
    }
  }
  cout << change << endl;
  for (it = mp1.begin(); it != mp1.end(); it++) {
    cout << it->first << " " << it->second << endl;
  }
  return 0;
}
