#include <bits/stdc++.h>
using namespace std;
int main() {
  int tt;
  cin >> tt;
  unordered_map<string, string> mp;
  unordered_set<string> s;
  for (int i = 0; i < tt; i++) {
    string s1;
    string s2;
    cin >> s1 >> s2;
    if (s.find(s1) == s.end()) {
      mp.insert({s1, s2});
      s.insert(s2);
    } else {
      for (auto &it : mp) {
        if (s1 == it.second) {
          it.second = s2;
          s.insert(s2);
        }
      }
    }
  }
  cout << mp.size() << endl;
  for (auto it : mp) {
    cout << it.first << " " << it.second << endl;
  }
  return 0;
}
