#include <bits/stdc++.h>
using namespace std;
char s[1010][3][50];
bool p[1010];
int main() {
  int n, i, j, c;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> s[i][1] >> s[i][2];
  memset(p, true, sizeof(p));
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (i != j) {
        if (strcmp(s[i][2], s[j][1]) == 0) {
          strcpy(s[i][2], s[j][2]);
          p[j] = false;
        }
      }
    }
  }
  for (i = 1, c = 0; i <= n; i++)
    if (p[i]) c++;
  cout << c << endl;
  for (i = 1; i <= n; i++) {
    if (p[i]) cout << s[i][1] << ' ' << s[i][2] << endl;
  }
  return 0;
}
