#include <bits/stdc++.h>
using namespace std;
string a[1001][3];
int main() {
  int n, m, k, t, jav = 0;
  cin >> n;
  for (k = 1; k <= n; k++) cin >> a[k][1] >> a[k][2];
  for (k = 1; k <= n - 1; k++)
    if (a[k][1] != "")
      for (t = k + 1; t <= n; t++)
        if (a[k][2] == a[t][1]) {
          a[k][2] = a[t][2];
          a[t][1] = "";
        }
  for (k = 1; k <= n; k++)
    if (a[k][1] != "") jav++;
  cout << jav << endl;
  for (k = 1; k <= n; k++)
    if (a[k][1] != "") cout << a[k][1] << " " << a[k][2] << endl;
  return 0;
}
