#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
  while (scanf("%d", &n) == 1) {
    map<string, string> m;
    set<string> _n;
    string o, ne;
    for (int i = 0; i < n; i++) {
      cin >> o >> ne;
      m[o] = ne;
      _n.insert(ne);
    }
    vector<pair<string, string> > ans;
    for (auto i : m) {
      string str = i.first;
      if (_n.find(str) != _n.end()) continue;
      while (m.count(str)) {
        str = m[str];
      }
      ans.push_back(make_pair(i.first, str));
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++)
      cout << ans[i].first << ' ' << ans[i].second << endl;
  }
  return 0;
}
