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