#include <bits/stdc++.h>
int main() {
  char old_h[1001][21], new_h[1001][21];
  int q, i, j;
  char temp[21];
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%s %s", old_h[i], new_h[i]);
  }
  for (i = 0; i < q; i++) {
    for (j = i + 1; j < q; j++) {
      if (strcmp(new_h[i], old_h[j]) == 0) {
        strcpy(temp, new_h[i]);
        strcpy(new_h[i], new_h[j]);
        strcpy(new_h[j], temp);
      }
    }
  }
  int count = 0;
  for (i = 0; i < q; i++) {
    if (strcmp(old_h[i], new_h[i]) != 0) count++;
  }
  printf("%d\n", count);
  for (i = 0; i < q; i++) {
    if (strcmp(old_h[i], new_h[i]) != 0) {
      printf("%s %s\n", old_h[i], new_h[i]);
    }
  }
}
