#include <bits/stdc++.h>
using namespace std;
auto main() -> int {
  auto ns = vector<vector<string>>{};
  auto N = 0;
  cin >> N;
  for (auto i = 0; i < N; ++i) {
    string tmp, tmp2;
    cin >> tmp >> tmp2;
    auto f = true;
    for (auto &n : ns) {
      if (std::count(begin(n), end(n), tmp) > 0) {
        n.push_back(tmp2);
        f = false;
      }
    }
    if (f) {
      ns.push_back(vector<string>{});
      (end(ns) - 1)->push_back(tmp);
      (end(ns) - 1)->push_back(tmp2);
    }
  }
  cout << ns.size() << '\n';
  for (auto &n : ns) {
    cout << *begin(n) << ' ' << *(end(n) - 1) << '\n';
  }
  return 0;
}
