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