#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, cnt = 0;
  cin >> n;
  vector<string> vec;
  map<string, string> mp, smp;
  while (n--) {
    string a, b;
    cin >> a >> b;
    if (smp.find(a) == smp.end()) {
      cnt++;
      mp[a] = b;
      smp[b] = a;
      vec.push_back(a);
      continue;
    }
    string p = smp[a];
    mp[p] = b;
    smp[b] = p;
  }
  cout << cnt << "\n";
  for (auto s : vec) cout << s << " " << mp[s] << "\n";
  return 0;
}
