#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  map<string, string> myMap;
  vector<string> names;
  for (int i = 0; i < N; i++) {
    string o, n;
    cin >> o >> n;
    if (myMap.find(o) == myMap.end()) {
      myMap.emplace(o, n);
      myMap.emplace(n, o);
      names.push_back(o);
    } else {
      string parent = myMap[o];
      myMap.erase(o);
      myMap[parent] = n;
      myMap.emplace(n, parent);
    }
  }
  cout << names.size() << endl;
  for (string value : names) {
    cout << value << " " << myMap[value] << endl;
  }
}
