#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, ct = 0;
  string old, nyu;
  map<string, string> child, par;
  map<string, bool> eee, der;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> old >> nyu;
    if (eee[old] == true) {
      child[par[old]] = nyu;
      par[nyu] = par[old];
      eee[nyu] = true;
    } else {
      eee[nyu] = true;
      par[nyu] = old;
      child[old] = nyu;
      ct++;
    }
  }
  map<string, string>::iterator it = child.begin();
  cout << ct << endl;
  for (it; it != child.end(); it++) {
    cout << it->first << " " << it->second << endl;
  }
  return 0;
}
