#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  set<pair<string, string>> s;
  while (n--) {
    string oldStr, newStr;
    cin >> oldStr >> newStr;
    auto it = s.lower_bound(make_pair(oldStr, ""));
    if (it != s.end() && it->first == oldStr) {
      s.insert(make_pair(newStr, it->second));
      s.erase(it);
    } else {
      s.insert(make_pair(newStr, oldStr));
    }
  }
  cout << s.size() << endl;
  for (auto ans : s) {
    cout << ans.second << " " << ans.first << endl;
  }
}
