#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<string> str1, str2;
  vector<string>::iterator it;
  string s1, s2;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    str1.push_back(s1);
    ;
    str2.push_back(s2);
    ;
  }
  int i = 0, j, count = 0;
  while (i < str1.size()) {
    if (str1[i] != "\0") {
      count++;
      while (find(str1.begin(), str1.end(), str2[i]) != str1.end()) {
        it = find(str1.begin(), str1.end(), str2[i]);
        j = it - str1.begin();
        str2[i] = str2[j];
        str1[j] = "\0";
        str2[j] = "\0";
      }
    }
    i++;
  }
  cout << count << "\n";
  for (i = 0; i < str1.size(); i++) {
    if (str1[i] != "\0") cout << str1[i] << " " << str2[i] << "\n";
  }
  return 0;
}
