#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  string a[2100];
  cin >> q;
  int next[2100];
  int pre[2100];
  for (int i = 1; i <= 2090; i++) next[i] = -1;
  for (int i = 1; i <= q; i++) {
    char str[30];
    cin >> str;
    a[2 * i - 1] = str;
    cin >> str;
    a[2 * i] = str;
    bool matched = false;
    for (int j = i - 1; j >= 1; j--) {
      if (a[2 * i - 1] == a[j * 2]) {
        next[pre[2 * j]] = i * 2;
        pre[2 * i] = pre[2 * j];
        matched = true;
        break;
      }
    }
    if (matched == false) {
      next[2 * i - 1] = 2 * i;
      pre[2 * i] = 2 * i - 1;
    }
  }
  int count = 0;
  for (int i = 1; i <= q; i++) {
    if (next[2 * i - 1] > 0) count++;
  }
  cout << count << endl;
  for (int i = 1; i <= q; i++) {
    if (next[2 * i - 1] > 0) {
      count--;
      cout << a[2 * i - 1] << " " << a[next[2 * i - 1]];
      if (count > 0) cout << endl;
    }
  }
  return 0;
}
