#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j;
  short q;
  char*** str;
  cin >> q;
  str = new char**[q * 2];
  for (short i = 0; i < q; i++) {
    str[i] = new char*[2];
    str[i][0] = new char[21];
    str[i][1] = new char[21];
  back:
    if (i >= q) break;
    cin >> str[i][0] >> str[i][1];
    for (int j = 0; j < i; j++)
      if (strcmp(str[i][1], str[j][0]) == 0 ||
          strcmp(str[i][1], str[j][1]) == 0) {
        q--;
        goto back;
      }
    for (int j = 0; j < i; j++)
      if (strcmp(str[i][0], str[j][1]) == 0) {
        q--;
        strcpy(str[j][1], str[i][1]);
        goto back;
      }
  }
  cout << q << endl;
  for (i = 0; i < q; i++) cout << str[i][0] << " " << str[i][1] << endl;
  return 0;
}
