#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, string> mp;
  map<string, string>::iterator j;
  for (int i = 0; i < n; i++) {
    string a, b;
    cin >> a >> b;
    if (i == 0)
      mp[a] = b;
    else {
      for (j = mp.begin(); j != mp.end(); ++j) {
        if (j->second == a) break;
      }
      if (j == mp.end())
        mp[a] = b;
      else
        mp[j->first] = b;
    }
  }
  cout << mp.size() << endl;
  for (j = mp.begin(); j != mp.end(); ++j)
    cout << j->first << " " << j->second << endl;
  return 0;
}
