#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string a, b;
  map<string, string> forw, bk;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    if (bk.find(a) != bk.end()) {
      string ori = bk[a];
      bk.erase(a);
      forw[ori] = b;
      bk[b] = ori;
    } else {
      forw[a] = b;
      bk[b] = a;
    }
  }
  cout << forw.size() << endl;
  for (auto p : forw) {
    cout << p.first << " " << p.second << endl;
  }
  return 0;
}
