#include <bits/stdc++.h>
using namespace std;
vector<pair<string, string>> temp;
map<string, bool> MV;
string extract(string x) {
  string res = "";
  for (int i = 0; i < int(temp.size()); i++) {
    if (temp[i].first == x && MV[x] == false) {
      res = temp[i].second;
      break;
    }
  }
  return res;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    string a, b;
    cin >> a >> b;
    temp.push_back(make_pair(a, b));
    MV[a] = false;
    MV[b] = false;
  }
  vector<pair<string, string>> ans;
  for (int j = 0; j < int(temp.size()); j++) {
    string src = temp[j].first;
    string dest = temp[j].second;
    if (MV[src] == false) {
      MV[src] = true;
      while (extract(dest).length() > 0) {
        string td = extract(dest);
        MV[dest] = true;
        dest = td;
      }
      ans.push_back(make_pair(src, dest));
    }
  }
  sort(ans.begin(), ans.end());
  cout << ans.size() << "\n";
  for (int i = 0; i < int(ans.size()); i++) {
    cout << ans[i].first << " " << ans[i].second << "\n";
  }
}
