#include <bits/stdc++.h>
using namespace std;
int vis[1005];
map<string, int> p;
string x[1005], y[1005];
vector<pair<string, string>> ans;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> x[i] >> y[i];
    p[x[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    if (vis[i]) continue;
    int now = i, pos = i;
    while (now) {
      vis[now] = 1;
      now = p[y[now]];
      if (now > 0) pos = now;
    }
    ans.push_back({x[i], y[pos]});
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
}
