#include <bits/stdc++.h>
using namespace std;
map<string, string> mmap;
map<string, string>::iterator it;
int main() {
  int t;
  cin >> t;
  while (t--) {
    string a;
    string b;
    cin >> a >> b;
    if (mmap[b] != "") {
      for (it = mmap.begin(); it != mmap.end(); it++) {
        if (it->first == b) {
          mmap.erase(it);
          break;
        }
      }
    }
    int flag = 0;
    for (it = mmap.begin(); it != mmap.end(); it++) {
      if (it->second == a) {
        it->second = b;
        flag = 1;
        break;
      }
    }
    if (!flag) mmap[a] = b;
  }
  int flag = 0;
  for (it = mmap.begin(); it != mmap.end(); it++)
    if (it->second == "") flag++;
  cout << mmap.size() - flag << endl;
  for (it = mmap.begin(); it != mmap.end(); it++)
    if (it->second != "") cout << it->first << " " << it->second << endl;
}
