#include <bits/stdc++.h>
std::unordered_map<std::string, std::string> m;
std::set<std::string> new_handle;
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int q;
  std::cin >> q;
  while (q--) {
    std::string o, n;
    std::cin >> o >> n;
    m[o] = n;
    new_handle.insert(n);
  }
  std::vector<std::pair<std::string, std::string>> ans;
  for (auto&& p : m) {
    if (new_handle.count(p.first)) continue;
    std::string t = p.first;
    while (m.count(t)) t = m[t];
    ans.push_back(std::make_pair(p.first, t));
  }
  std::cout << ans.size() << '\n';
  for (auto p : ans) std::cout << p.first << ' ' << p.second << '\n';
  return 0;
}
