#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int loop = 0;
  cin >> loop;
  map<string, string> handles;
  vector<string> handle;
  while (loop--) {
    string value, key;
    cin >> value >> key;
    handle.push_back(value);
    if (handles[value] != "") {
      handles[key] = handles[value];
      handles[handles[value]] = key;
      handle.pop_back();
    } else {
      handles[key] = value;
      handles[value] = key;
    }
  }
  cout << handle.size() << endl;
  for (auto it : handle) {
    cout << it << " " << handles[it] << endl;
  }
}
