#include <bits/stdc++.h>
using namespace std;
map<string, bool> root;
vector<string> start;
map<string, vector<string>> adj;
string dfs(string s) {
  if (!adj[s].size()) return s;
  string ret;
  for (auto v : adj[s]) ret = dfs(v);
  return ret;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string x, y;
    cin >> x >> y;
    if (!root[x]) {
      start.push_back(x);
      root[x] = 1;
    }
    root[y] = 1;
    adj[x].push_back(y);
  }
  cout << start.size() << '\n';
  for (auto x : start) {
    string y = dfs(x);
    cout << x << ' ' << y << '\n';
  }
  return 0;
}
