#include <bits/stdc++.h>
using namespace std;
char s1[1010][30], s2[1010][30];
bool is[1010];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1[i] >> s2[i];
  }
  char str[30];
  int cnt = n;
  for (int i = 0; i < n; i++) {
    if (is[i]) continue;
    memcpy(str, s2[i], sizeof(s2[i]));
    int j = i + 1;
    while (j < n) {
      if (strcmp(s1[j], str) == 0) {
        is[j] = 1;
        cnt--;
        memcpy(str, s2[j], sizeof(s2[j]));
      }
      j++;
    }
    memcpy(s2[i], str, sizeof(str));
  }
  cout << cnt << endl;
  for (int i = 0; i < n; i++) {
    if (!is[i]) cout << s1[i] << " " << s2[i] << endl;
  }
  return 0;
}
