#include <bits/stdc++.h>
using namespace std;
int n, ans;
bool C[1100];
string Old[1100], New[1100];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> Old[i] >> New[i];
  ans = n;
  for (int i = 0; i < n - 1; i++) {
    if (C[i]) continue;
    for (int j = i + 1; j < n; j++) {
      if (!C[j] && New[i] == Old[j]) {
        New[i] = New[j];
        ans--;
        C[j] = true;
      }
    }
  }
  cout << ans << "\n";
  for (int i = 0; i < n; i++) {
    if (!C[i]) cout << Old[i] << " " << New[i] << "\n";
  }
}
