#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1005;
int n, cnt;
int st[N], ed[N];
char od[N][25], nw[N][25];
map<string, int> m;
int main() {
  while (scanf("%d", &n) != EOF) {
    cnt = 0;
    m.clear();
    memset(st, -1, sizeof(st));
    memset(ed, -1, sizeof(ed));
    string sa, sb;
    for (int i = 1; i <= n; i++) {
      scanf("%s %s", od[i], nw[i]);
      sa = od[i];
      sb = nw[i];
      if (m[sa] == 0) {
        ++cnt;
        st[cnt] = i;
        ed[cnt] = i;
        m[sa] = cnt;
        m[sb] = cnt;
      } else {
        ed[m[sa]] = i;
        m[sb] = m[sa];
      }
    }
    printf("%d\n", cnt);
    for (int i = 1; i <= cnt; i++) {
      printf("%s %s\n", od[st[i]], nw[ed[i]]);
    }
  }
  return 0;
}
