#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
int main() {
  map<string, string> mp;
  map<string, bool> vis;
  pair<string, string> p[N];
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> p[i].first >> p[i].second;
  }
  for (int i = 0; i < n; i++) {
    if (!vis[p[i].first] && !vis[p[i].second]) {
      vis[p[i].first] = 1;
      vis[p[i].second] = 1;
      mp[p[i].first] = p[i].second;
    } else {
      vis[p[i].second] = 1;
      for (auto it : mp) {
        if (it.second == p[i].first) mp[it.first] = p[i].second;
      }
    }
  }
  cout << mp.size() << endl;
  for (auto i : mp) cout << i.first << " " << i.second << endl;
  return 0;
}
