#include <bits/stdc++.h>
using namespace std;
map<string, string> mp;
map<string, string>::iterator it;
void init() { mp.clear(); }
int main() {
  int n;
  cin.sync_with_stdio(0);
  while (cin >> n) {
    init();
    string cc, dd;
    while (n--) {
      cin >> cc >> dd;
      it = mp.find(cc);
      if (it == mp.end()) {
        mp[dd] = cc;
      } else {
        mp[dd] = it->second;
        mp.erase(it);
      }
    }
    cout << mp.size() << endl;
    map<string, string>::iterator it;
    for (it = mp.begin(); it != mp.end(); it++) {
      cout << it->second << " " << it->first << endl;
    }
  }
  return 0;
}
