#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  map<string, string> m;
  pair<std::map<string, string>::iterator, bool> ret;
  map<string, string>::iterator it;
  scanf("%d", &t);
  while (t--) {
    string a, b;
    cin >> a;
    cin >> b;
    it = m.find(a);
    if (it != m.end()) {
      string c = it->second;
      m.erase(it);
      m[b] = c;
    } else
      m[b] = a;
  }
  printf("%d\n", m.size());
  for (it = m.begin(); it != m.end(); it++) {
    cout << it->second << " " << it->first << endl;
  }
  return 0;
}
