#include <bits/stdc++.h>
using namespace std;
int n, cnt;
string s1, s2;
map<string, string> ma1;
map<string, string> ma2;
int main() {
  while (~scanf("%d", &n)) {
    ma1.clear();
    ma2.clear();
    while (n--) {
      cin >> s1 >> s2;
      if (ma2.find(s1) == ma2.end()) {
        ma1[s1] = s2;
        ma2[s2] = s1;
      } else {
        ma1[ma2[s1]] = s2;
        ma2[s2] = ma2[s1];
        ma2.erase(s1);
      }
    }
    cout << ma1.size() << endl;
    for (map<string, string>::iterator it = ma1.begin(); it != ma1.end();
         ++it) {
      cout << it->first << " " << it->second << endl;
    }
  }
  return 0;
}
