#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, ans = 0;
  cin >> n;
  string cur1[1010], cur2;
  unordered_map<string, string> m;
  unordered_set<string> s;
  for (int i = 0; i < n; ++i) {
    cin >> cur1[i] >> cur2;
    s.insert(cur2);
    m.insert(make_pair(cur1[i], cur2));
  }
  for (int i = 0; i < n; ++i) {
    if (!s.count(cur1[i])) ++ans;
  }
  cout << ans << endl;
  for (int i = 0; i < n; ++i) {
    if (!s.count(cur1[i])) {
      cout << cur1[i] << ' ';
      string op = m.find(cur1[i])->second;
      while (true) {
        if (!m.count(op))
          break;
        else
          op = m.find(op)->second;
      }
      cout << op << endl;
    }
  }
  cin >> n;
  return 0;
}
