#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, flag;
  string str1, str2;
  map<string, string> mymap;
  map<string, string>::iterator it;
  cin >> n;
  while (n--) {
    flag = 0;
    cin >> str1 >> str2;
    it = mymap.begin();
    while (it != mymap.end()) {
      if (it->second == str1) {
        flag = 1;
        it->second = str2;
        break;
        ;
      }
      it++;
    }
    if (flag == 0) {
      mymap[str1] = str2;
    }
  }
  cout << mymap.size() << "\n";
  it = mymap.begin();
  while (it != mymap.end()) {
    cout << it->first << " " << it->second << "\n";
    it++;
  }
  return 0;
}
