#include <bits/stdc++.h>
using namespace std;
vector<pair<string, string> > myvector;
map<string, string> mymap;
int n;
int main() {
  string temp1, temp2, wtf;
  cin >> n;
  set<string> myset;
  for (int x = 0; x < n; x++) {
    cin >> temp1 >> temp2;
    mymap[temp1] = temp2;
    myset.insert(temp2);
  }
  map<string, string>::iterator it = mymap.begin();
  for (; it != mymap.end(); it++) {
    if (myset.count(it->first)) continue;
    string ATM = it->first;
    while (mymap.count(ATM)) ATM = mymap[ATM];
    myvector.push_back(make_pair(it->first, ATM));
  }
  cout << myvector.size() << endl;
  for (int i = 0; i < myvector.size(); i++) {
    cout << myvector[i].first << " " << myvector[i].second << endl;
  }
  return 0;
}
