#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, cnt = 0, flag = 0;
  scanf("%d", &q);
  char old[1005][25], new1[1005][25], temp[25];
  for (int i = 0; i < q; i++) {
    scanf("%s", temp);
    if (i == 0) {
      strcpy(old[cnt], temp);
      scanf("%s", temp);
      strcpy(new1[cnt++], temp);
      continue;
    }
    for (int j = 0; j < cnt; j++)
      if (strcmp(new1[j], temp) == 0) {
        scanf("%s", temp);
        strcpy(new1[j], temp);
        flag = 1;
        break;
      }
    if (flag == 1) {
      flag = 0;
      continue;
    } else {
      strcpy(old[cnt], temp);
      scanf("%s", temp);
      strcpy(new1[cnt++], temp);
    }
  }
  printf("%d\n", cnt);
  for (int i = 0; i < cnt; ++i) printf("%s %s\n", old[i], new1[i]);
  return 0;
}
