#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  string newu, oldu;
  map<string, string> usernames;
  for (int i = 0; i < q; i++) {
    cin >> oldu;
    cin >> newu;
    usernames.insert(pair<string, string>(oldu, newu));
    auto itr = usernames.begin();
    for (int j = 0; j < usernames.size(); j++) {
      if (oldu == itr->second) {
        itr->second = newu;
        usernames.erase(oldu);
      }
      itr++;
    }
  }
  cout << usernames.size() << endl;
  for (auto itr = usernames.begin(); itr != usernames.end(); itr++) {
    cout << itr->first << " " << itr->second << endl;
  }
  return 0;
}
