#include <bits/stdc++.h>
int main(void) {
  int i, j, k, l, n, p, q;
  char oldname[1100][25], newname[1100][25];
  scanf("%d", &n);
  getchar();
  for (i = 0; i < n; i++) {
    scanf("%s %s", &oldname[i], &newname[i]);
  }
  l = n - 2;
  i = 1;
  p = 0;
  q = 0;
  while (i <= l) {
    for (j = 0; j < i; j++) {
      if (!strcmp(oldname[i], newname[j])) {
        strcpy(newname[j], newname[i]);
        for (k = i; k <= l; k++) {
          strcpy(oldname[k], oldname[k + 1]);
          strcpy(newname[k], newname[k + 1]);
        }
        l--;
        p++;
        break;
      }
    }
    if (!p) {
      i++;
    } else {
      p = 0;
    }
  }
  for (j = 0; j < i; j++) {
    if (!strcmp(oldname[i], newname[j])) {
      strcpy(newname[j], newname[i]);
      q++;
      break;
    }
  }
  if (q == 0) {
    i++;
  }
  if (n == 1) {
    i = 1;
  }
  printf("%d\n", i);
  for (k = 0; k < i; k++) {
    printf("%s %s\n", oldname[k], newname[k]);
  }
  return 0;
}
