#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(nullptr);
  int n;
  string a, b;
  map<string, string> ans;
  map<string, string> rev;
  cin >> n;
  while (n--) {
    cin >> a >> b;
    if (rev.find(a) == rev.end()) {
      ans[a] = b;
      rev[b] = a;
    } else {
      string orig = rev[a];
      ans[orig] = b;
      rev[b] = orig;
    }
  }
  cout << ans.size() << '\n';
  for (auto &p : ans) cout << p.first << ' ' << p.second << '\n';
  return 0;
}
