#include <bits/stdc++.h>
using namespace std;
const int maxn = 1005;
map<string, int> toi;
map<int, string> tos, name;
int ton[maxn], tot, too[maxn];
string a, b;
int main() {
  int q, tmp;
  tot = 0;
  cin >> q;
  while (q--) {
    cin >> a >> b;
    if (toi.find(a) == toi.end()) {
      toi[a] = tot;
      toi[b] = tot;
      name[tot] = a;
      tos[tot++] = b;
    } else {
      tmp = toi[a];
      toi[b] = tmp;
      tos[tmp] = b;
    }
  }
  cout << tot << endl;
  for (q = 0; q < tot; q++) {
    cout << name[q] << " " << tos[q] << endl;
  }
  return 0;
}
