#include <bits/stdc++.h>
using namespace std;
int p;
string a, b;
map<string, string> _m;
map<string, int> _mm;
map<string, string>::iterator it;
int c;
int main() {
  while (cin >> p) {
    _m.clear();
    _mm.clear();
    c = 0;
    while (p--) {
      cin >> a >> b;
      if (_m[a] == "") {
        _m[b] = a;
      } else {
        _m[b] = _m[a];
      }
      _mm[a] = 1;
    }
    for (it = _m.begin(); it != _m.end(); it++) {
      if (it->second == "") {
        c++;
      }
    }
    cout << c << endl;
    for (it = _m.begin(); it != _m.end(); it++) {
      if (_mm[it->first] != 1) cout << it->second << " " << it->first << endl;
    }
  }
  return 0;
}
