#include <bits/stdc++.h>
using namespace std;
map<string, int> mp;
int tot;
string str[2222];
int n;
int nxt[2222];
vector<pair<int, int> > ans;
string a, b;
int main() {
  int i, j;
  memset(nxt, -1, sizeof(nxt));
  while (cin >> n) {
    for (i = 0; i < n; i++) {
      cin >> a >> b;
      if (mp.find(a) == mp.end()) {
        mp[a] = tot;
        str[tot++] = a;
      }
      if (mp.find(b) == mp.end()) {
        mp[b] = tot;
        str[tot++] = b;
      }
      int l = mp[a], r = mp[b];
      nxt[l] = r;
    }
    for (i = 0; i < tot; i++) {
      int t = i;
      while (nxt[t] != -1) {
        int p = t;
        t = nxt[t];
        nxt[p] = -1;
      }
      if (t != i) ans.push_back(make_pair(i, t));
    }
    cout << ans.size() << endl;
    for (i = 0; i < (int)ans.size(); i++)
      cout << str[ans[i].first] << " " << str[ans[i].second] << endl;
  }
  return 0;
}
