#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  vector<pair<string, string> > v;
  while (q) {
    pair<string, string> p;
    cin >> p.first;
    cin >> p.second;
    bool flag = true;
    for (int i = 0; i < v.size(); i++) {
      if (v[i].second == p.first) {
        flag = false;
        v[i].second = p.second;
      }
    }
    if (flag) v.push_back(p);
    q--;
  }
  cout << v.size() << endl;
  for (int i = 0; i < v.size(); i++)
    cout << v[i].first << " " << v[i].second << endl;
}
