#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> m;
  map<string, string>::iterator it;
  int n, flag = 0;
  string c1, c2;
  cin >> n;
  for (int i = 0; i < n; i++) {
    flag = 0;
    cin >> c1 >> c2;
    for (it = m.begin(); it != m.end(); it++) {
      if ((*it).second == c1) {
        (*it).second = c2;
        flag = 1;
        break;
      }
    }
    if (flag == 0) {
      m[c1] = c2;
    }
  }
  cout << m.size() << "\n";
  for (it = m.begin(); it != m.end(); it++) {
    cout << (*it).first << " " << (*it).second << "\n";
  }
  return 0;
}
