#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<pair<string, string> > v;
  int n, flag = 0, ans = 0;
  string s, t;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s >> t;
    flag = 0;
    for (int j = 0; j < v.size(); j++) {
      if (s == v[j].second) {
        v[j].second = t;
        flag = 1;
        break;
      }
    }
    if (!flag) {
      ans++;
      v.push_back(make_pair(s, t));
    }
  }
  cout << ans << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << v[i].first << " " << v[i].second << endl;
  }
}
