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