#include <bits/stdc++.h>
int max(int a, int b) {
  if (a > b)
    return a;
  else
    return b;
}
int main() {
  char Old[1001][21], New[1001][21], CheckNew[21], NewOne[21];
  int n, q, count = 0, Flag = 0, i, j;
  scanf("%d", &q);
  for (i = 1; i <= q; i++) {
    Flag = 0;
    scanf("%s %s", CheckNew, NewOne);
    for (j = 0; j < count; j++)
      if (strcmp(New[j], CheckNew) == 0) {
        strcpy(New[j], NewOne);
        Flag = 1;
        break;
      }
    if (Flag == 0)
      for (j = 0; j < count; j++)
        if (strcmp(Old[j], CheckNew) == 0) {
          strcpy(New[j], NewOne);
          Flag = 1;
          break;
        }
    if (Flag == 0) {
      strcpy(Old[count], CheckNew);
      strcpy(New[count++], NewOne);
    }
  }
  printf("%d\n", count);
  for (i = 0; i < count; i++) printf("%s %s\n", Old[i], New[i]);
  return 0;
}
