#include <bits/stdc++.h>
using namespace std;
int main() {
  long q;
  cin >> q;
  map<string, string> mp, final;
  unordered_set<string> s;
  while (q--) {
    string old, newd;
    cin >> old >> newd;
    if (s.find(old) != s.end()) {
      if (s.find(newd) == s.end()) {
        mp[old] = newd;
        map<string, string>::iterator itr;
        for (itr = final.begin(); itr != final.end(); ++itr) {
          if (itr->second == old) {
            itr->second = newd;
          }
        }
        s.insert(newd);
      } else {
      }
    } else {
      if (s.find(newd) == s.end()) {
        mp[old] = newd;
        final[old] = newd;
        s.insert(newd);
        s.insert(old);
      } else {
      }
    }
  }
  cout << final.size() << endl;
  map<string, string>::iterator itr;
  for (itr = final.begin(); itr != final.end(); ++itr) {
    cout << itr->first << " " << itr->second << endl;
  }
  cout << endl;
  return 0;
}
