#include <bits/stdc++.h>
typedef struct isim {
  char eski[100], yeni[100];
} isim;
int main() {
  int n, i, j, s = 0, h = 0;
  char a[100], b[100];
  isim str[1000];
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    h = 0;
    scanf("%s %s", a, b);
    for (j = 0; j < i; j++) {
      if (strcmp(str[j].yeni, a) == 0) strcpy(str[j].yeni, b), h = 1;
    }
    if (h != 1) {
      strcpy(str[s].eski, a);
      strcpy(str[s].yeni, b);
      s++;
    }
  }
  printf("%d\n", s);
  for (i = 0; i < s; i++) printf("%s %s\n", str[i].eski, str[i].yeni);
  return 0;
}
