#include <bits/stdc++.h>
using namespace std;
vector<pair<string, string> > vect;
int main() {
  int q;
  cin >> q;
  for (int i = (0); i < (q); ++i) {
    string o, n;
    cin >> o >> n;
    if (vect.size() == 0)
      vect.push_back(make_pair(o, n));
    else {
      bool exist = false;
      for (int j = (0); j < (vect.size()); ++j) {
        if (vect[j].second == o) {
          exist = true;
          vect[j].second = n;
        }
      }
      if (!exist) {
        vect.push_back(make_pair(o, n));
      }
    }
  }
  cout << vect.size() << '\n';
  for (auto x : vect) {
    cout << x.first << " " << x.second << '\n';
  }
  return 0;
}
