#include <bits/stdc++.h>
struct Tchange {
  char Old[25], New[25];
  bool repeated;
};
int main() {
  struct Tchange handles[1005];
  int q, cont = 0;
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    scanf("%s %s", handles[i].Old, handles[i].New);
    handles[i].repeated = false;
  }
  for (int i = 0; i < q; i++)
    for (int j = i + 1; j < q; j++)
      if (!(strcmp(handles[j].Old, handles[i].New))) {
        strcpy(handles[i].New, handles[j].New);
        handles[j].repeated = 1;
      }
  for (int i = 0; i < q; i++)
    if (!(handles[i].repeated)) cont++;
  int i = 0;
  int loop = 0;
  printf("%d\n", cont);
  while (i < cont) {
    if (!(handles[loop].repeated)) {
      printf("%s %s\n", handles[loop].Old, handles[loop].New);
      i++;
    }
    loop++;
  }
  return 0;
}
