#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  scanf("%d", &n);
  map<string, string> val;
  map<string, string> cpy;
  while (n--) {
    string a, b;
    cin >> a >> b;
    if (cpy.count(a) >= 1) {
      string temp = cpy[a];
      val[temp] = b;
      cpy.erase(a);
      cpy[b] = temp;
    } else {
      val[a] = b;
      cpy[b] = a;
    }
  }
  printf("%d\n", cpy.size());
  map<string, string>::iterator it = cpy.begin();
  while (it != cpy.end()) {
    cout << it->second << " " << it->first << endl;
    it++;
  }
}
