#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  string c, d;
  string a[q], b[q];
  int l = 0;
  for (int i = 1; i <= q; i++) {
    cin >> c >> d;
    bool t = 0;
    for (int j = l - 1; j >= 0 && l >= 1; j--)
      if (b[j] == c) {
        b[j] = d;
        t = 1;
        break;
      }
    if (t == 0) a[l] = c, b[l] = d, l++;
  }
  cout << l << endl;
  for (int i = 0; i < l; i++) cout << a[i] << " " << b[i] << endl;
}
