#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string one, two;
  map<string, string> m;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> one >> two;
    bool found = false;
    for (map<string, string>::iterator it = m.begin(); it != m.end(); ++it) {
      if (it->second == one) {
        it->second = two;
        found = true;
      }
    }
    if (!found) {
      m.insert(pair<string, string>(one, two));
    }
  }
  cout << m.size() << "\n";
  for (map<string, string>::iterator it = m.begin(); it != m.end(); ++it) {
    cout << it->first << " " << it->second << "\n";
  }
  cout << flush;
  return 0;
}
