#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  map<string, string> myMap;
  int ans = 0;
  for (int i = 0; i < q; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    myMap[s1] = s2;
  }
  map<string, string>::iterator it = myMap.begin();
  while (it != myMap.end()) {
    if (myMap.count(it->second) > 0) {
      map<string, string>::iterator it0 = myMap.find(it->second);
      myMap[it->first] = myMap[it0->first];
      myMap.erase(it0);
    } else {
      *it++;
    }
  }
  it = myMap.begin();
  cout << myMap.size() << endl;
  for (int i = 0; i < myMap.size(); i++) {
    cout << it->first << ' ' << it->second << endl;
    *it++;
  }
  return 0;
}
