#include <bits/stdc++.h>
using namespace std;
int max1(int a, int b) { return a > b ? a : b; }
char a[1001][21], b[1001][21], x[21];
int mark[1001], q, i, j;
int main() {
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    scanf("%s %s", a[i], b[i]);
  }
  for (i = 0; i < q; i++) {
    memset(x, 0, 21);
    strcpy(x, b[i]);
    if (mark[i] == 0) {
      for (j = i + 1; j < q; j++) {
        if (strcmp(a[j], x) == 0) {
          mark[j] = 1;
          memset(x, 0, 21);
          strcpy(x, b[j]);
        }
      }
    }
    for (j = 0; j < 21; j++) b[i][j] = 0;
    strcpy(b[i], x);
  }
  int count1 = 0;
  for (i = 0; i < q; i++) {
    if (mark[i] == 0) count1++;
  }
  printf("%d\n", count1);
  for (i = 0; i < q; i++) {
    if (mark[i] == 0) printf("%s %s\n", a[i], b[i]);
  }
  return 0;
}
