#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, j, k = -1;
  string f, t;
  cin >> n;
  string* a1 = new string[n];
  string* an = new string[n];
  for (int i = 0; i < n; i++) {
    cin >> f >> t;
    for (j = 0; j < i; j++)
      if (f == an[j]) break;
    if (j == i) {
      an[++k] = t;
      a1[k] = f;
    } else
      an[j] = t;
  }
  cout << k + 1 << endl;
  for (int i = 0; i <= k; i++) cout << a1[i] << " " << an[i] << endl;
  return 0;
}
