#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T sqr(T n) {
  return n * n;
}
int main() {
  vector<pair<string, string>> vii;
  int n;
  cin >> n;
  string str, str1;
  map<string, string> sii;
  for (int j = 0; j < n; j++) {
    cin >> str >> str1;
    vii.push_back(make_pair(str, str1));
  }
  int lix = 0;
  bool m[1111] = {false};
  for (int j = 0; j < n; j++) {
    for (int k = 0; k < n; k++) {
      if (vii[j].second == vii[k].first) {
        vii[j].second = vii[k].second;
        vii[k].second.clear();
        vii[k].first.clear();
      }
    }
  }
  for (int k = 0; k < n; k++) {
    if (vii[k].first.size() != 0 && vii[k].second.size() != 0) lix++;
  }
  cout << lix << endl;
  for (int k = 0; k < n; k++) {
    if (vii[k].first.size() != 0 && vii[k].second.size() != 0)
      cout << vii[k].first << ' ' << vii[k].second << endl;
  }
  return 0;
}
