#include <bits/stdc++.h>
using namespace std;
int q;
map<string, string> M, par;
vector<pair<string, string> > ans;
int main() {
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    string old, dsfasdfa;
    cin >> old >> dsfasdfa;
    bool flag = false;
    if (par[old].empty()) {
      par[dsfasdfa] = old;
      flag = true;
    }
    if (!flag) {
      M[par[old]] = dsfasdfa;
      par[dsfasdfa] = par[old];
    } else
      M[old] = dsfasdfa;
  }
  for (map<string, string>::iterator it = M.begin(); it != M.end(); ++it) {
    ans.push_back(make_pair(it->first, it->second));
  }
  cout << ans.size() << endl;
  for (int i = 0; i < (int)ans.size(); ++i)
    cout << ans[i].first << ' ' << ans[i].second << endl;
  return 0;
}
