#include <bits/stdc++.h>
struct node {
  char oldname[25];
  char newname[25];
} user[1010];
int main(void) {
  int n, num = 0;
  char newname[25], oldname[25];
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%s%s", oldname, newname);
    int flag = 0;
    for (int j = 0; j < num; j++) {
      if (strcmp(user[j].newname, oldname) == 0) {
        flag = 1;
        strcpy(user[j].newname, newname);
        break;
      }
    }
    if (!flag) {
      strcpy(user[num].newname, newname);
      strcpy(user[num].oldname, oldname);
      num++;
    }
  }
  printf("%d\n", num);
  for (int i = 0; i < num; i++) {
    printf("%s %s\n", user[i].oldname, user[i].newname);
  }
  return 0;
}
