#include <bits/stdc++.h>
using namespace std;
map<string, int> Map;
char str[2200][22];
int p[2200], q[2200];
int main() {
  int num, n, k1, k2, cnt;
  char s1[22], s2[22];
  while (scanf("%d", &n) != EOF) {
    memset(p, 0, sizeof(p));
    memset(q, 0, sizeof(q));
    cnt = 1;
    num = 0;
    while (n--) {
      scanf("%s %s", s1, s2);
      if (Map[s2] > 0) continue;
      if ((k1 = Map[s1]) > 0) {
        Map[s1] = 0;
        strcpy(str[cnt++], s2);
        p[q[k1]] = cnt - 1;
        q[cnt - 1] = q[k1];
        Map[s2] = cnt - 1;
      } else {
        strcpy(str[cnt++], s1);
        strcpy(str[cnt++], s2);
        p[cnt - 2] = cnt - 1;
        q[cnt - 1] = cnt - 2;
        Map[s2] = cnt - 1;
        num++;
      }
    }
    printf("%d\n", num);
    int i;
    for (i = 0; i < cnt; i++)
      if (p[i]) printf("%s %s\n", str[i], str[p[i]]);
  }
  return 0;
}
