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