#include <bits/stdc++.h>
using namespace std;
int main() {
  string old[1000], ne[1000];
  vector<pair<string, string> > ans;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) cin >> old[i] >> ne[i];
  for (int i = 0; i < q; i++) {
    vector<string> x;
    if (old[i] == ".") continue;
    x.push_back(old[i]);
    x.push_back(ne[i]);
    for (int j = i + 1; j < q; j++) {
      if (x.back() == old[j]) {
        old[j] = ".";
        x.push_back(ne[j]);
      }
    }
    if (x.front() != x.back()) ans.push_back(make_pair(x.front(), x.back()));
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i].first << " " << ans[i].second << endl;
  return 0;
}
