#include <bits/stdc++.h>
int main() {
  static char a[1001][21];
  static char b[1001][21];
  char aim1[21];
  char aim2[21];
  int n, m = 1;
  int i, j;
  int flag;
  scanf("%d", &n);
  scanf("%s%s", a[0], b[0]);
  for (i = 1; i < n; i++) {
    flag = 0;
    scanf("%s%s", aim1, aim2);
    for (j = 0; j < m; j++) {
      if (strcmp(aim1, b[j]) == 0) {
        flag = 1;
        break;
      }
    }
    if (flag)
      strcpy(b[j], aim2);
    else {
      strcpy(a[m], aim1);
      strcpy(b[m], aim2);
      ++m;
    }
  }
  printf("%d\n", m);
  for (i = 0; i < m; i++) printf("%s %s\n", a[i], b[i]);
}
