#include <bits/stdc++.h>
using namespace std;
vector<string> maphandle[1010];
vector<pair<string, int> > nohandle;
int num(string s) {
  for (int i = 0; i < nohandle.size(); i++) {
    if (s == nohandle[i].first) {
      return nohandle[i].second;
    }
  }
  return -1;
}
int main() {
  int q;
  cin >> q;
  string s, r;
  int uniqcount = 0;
  for (int i = 0; i < q; i++) {
    cin >> s >> r;
    int vectno = num(s);
    if (vectno == -1) {
      maphandle[uniqcount].push_back(s);
      maphandle[uniqcount].push_back(r);
      nohandle.push_back(make_pair(r, uniqcount));
      uniqcount++;
    } else {
      maphandle[vectno].push_back(r);
      nohandle.push_back(make_pair(r, vectno));
    }
  }
  cout << uniqcount << endl;
  for (int hi = 0; hi < uniqcount; hi++) {
    int l = maphandle[hi].size() - 1;
    cout << maphandle[hi][0] << " " << maphandle[hi][l] << endl;
  }
  return 0;
}
