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