#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int q;
  cin >> q;
  string a[1010], b[1010], c[1010];
  for (long long i = 1; i <= q; i++) cin >> a[i] >> b[i], c[i] = a[i];
  int f[1010];
  for (long long i = 1; i <= q; i++) {
    f[i] = i;
    for (long long j = 1; j <= q; j++) {
      if (b[f[i]] == a[j]) {
        f[i] = (int)j;
      }
    }
  }
  int res = 0;
  set<string> use;
  use.insert(b[f[1]]);
  a[1] = b[f[1]];
  for (long long i = 1; i <= q; i++) {
    set<string> m = use;
    m.insert(b[f[i]]);
    if (m.size() > use.size()) {
      a[i] = b[f[i]];
      use = m;
    }
  }
  for (long long i = 1; i <= q; i++)
    if (a[i] != c[i]) res++;
  cout << res << endl;
  for (long long i = 1; i <= q; i++)
    if (a[i] != c[i]) cout << c[i] << " " << a[i] << endl;
  return 0;
}
