#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> hh;
  map<string, string>::iterator it;
  int n;
  string a, b, c;
  cin >> n;
  while (n--) {
    cin >> a >> b;
    it = hh.find(a);
    if (it == hh.end())
      hh[b] = a;
    else {
      c = it->second;
      hh.erase(it);
      hh[b] = c;
    }
  }
  cout << hh.size() << endl;
  for (it = hh.begin(); it != hh.end(); it++)
    cout << it->second << ' ' << it->first << endl;
  return 0;
}
