#include <bits/stdc++.h>
using namespace std;
int main() {
  int numberOfRequests;
  map<string, string> loginHandles;
  cin >> numberOfRequests;
  for (int i = 0; i < numberOfRequests; i++) {
    string currentHandle, newHandle;
    cin >> currentHandle >> newHandle;
    if (loginHandles.find(currentHandle) == loginHandles.end()) {
      loginHandles.insert(pair<string, string>(newHandle, currentHandle));
    } else {
      string oldHandle;
      oldHandle = loginHandles.find(currentHandle)->second;
      loginHandles.erase(loginHandles.find(currentHandle));
      loginHandles.insert(pair<string, string>(newHandle, oldHandle));
    }
  }
  cout << loginHandles.size() << endl;
  for (map<string, string>::iterator it = loginHandles.begin();
       it != loginHandles.end(); it++) {
    cout << it->second << " " << it->first << endl;
  }
  return 0;
}
