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