#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, count = 0;
  string str[2000];
  cin >> n;
  for (int i = 0; i < 2 * n; i++) cin >> str[i];
  for (int i = 2 * n - 1; i > 0; i -= 2) {
    for (int j = 0; j < 2 * n; j += 2) {
      if (str[i] == str[j]) {
        str[i] = str[j + 1];
        str[j] = "NULL";
        count++;
      }
    }
  }
  cout << n - count << endl;
  for (int i = 0; i < 2 * n; i += 2) {
    if (str[i] != "NULL") {
      cout << str[i] << " " << str[i + 1] << endl;
    }
  }
  return 0;
}
