#include <bits/stdc++.h>
struct firstLast {
  char first[25], last[25];
};
int main() {
  int n;
  scanf("%d", &n);
  char s[n][2][21];
  char s1, s2;
  for (int i = 0; i < n; i++) {
    scanf("%s %s", s[i][0], s[i][1]);
  }
  struct firstLast arr[n + 1];
  int totalCount = 0;
  int isAdded[n];
  for (int i = 0; i <= n; i++) {
    isAdded[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    if (isAdded[i]) continue;
    char firstName[25], LastName[25];
    strcpy(firstName, s[i][0]);
    strcpy(LastName, s[i][1]);
    for (int j = i + 1; j < n; j++) {
      if (!strcmp(LastName, s[j][0])) {
        strcpy(LastName, s[j][1]);
        isAdded[j] = 1;
      }
    }
    struct firstLast var;
    strcpy(var.first, firstName);
    strcpy(var.last, LastName);
    arr[totalCount] = var;
    totalCount++;
  }
  printf("%d\n", totalCount);
  for (int i = 0; i < totalCount; i++) {
    printf("%s %s\n", arr[i].first, arr[i].last);
  }
}
