#include <bits/stdc++.h>
using namespace std;
struct Rename {
  char oldName[21];
  char newName[21];
};
int main() {
  Rename renames[1001 + 1];
  int insertIn = 1;
  int q;
  cin >> q;
  unordered_map<string, int> nameToIndex;
  for (int i = 0; i < q; ++i) {
    Rename newRename;
    cin >> newRename.oldName >> newRename.newName;
    int index = nameToIndex[newRename.oldName];
    if (index == 0) {
      renames[insertIn] = newRename;
      nameToIndex[newRename.newName] = insertIn;
      ++insertIn;
    } else {
      memcpy(renames[index].newName, newRename.newName, 21);
      nameToIndex[newRename.newName] = index;
    }
  }
  cout << insertIn - 1 << endl;
  for (int i = 1; i < insertIn; ++i) {
    cout << renames[i].oldName << " " << renames[i].newName << endl;
  }
  return 0;
}
