#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, c = 0;
  pair<string, string> a[1002];
  map<string, string> mp;
  map<string, bool> mpa;
  string x;
  string y;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x >> y;
    mp[x] = y;
    a[i].first = x;
    a[i].second = y;
  }
  for (int i = n - 1; i >= 0; i--) {
    for (int j = n - 1; j >= 0; j--) {
      if (a[i].first == a[j].second) {
        c++;
        mp[a[j].first] = mp[a[i].first];
        mpa[a[i].first] = true;
      }
    }
  }
  cout << n - c << endl;
  for (int i = 0; i < n; i++) {
    if (mpa[a[i].first] != true)
      cout << a[i].first << " " << mp[a[i].first] << endl;
  }
  return 0;
}
