#include <bits/stdc++.h>
using namespace std;
map<string, string> M;
int Num = 0;
void input();
void output();
int main() {
  input();
  output();
  return 0;
}
void input() {
  string str1, str2;
  int N;
  cin >> N;
  while (N--) {
    bool nofind = true;
    cin >> str1;
    cin >> str2;
    for (map<string, string>::iterator it = M.begin(); it != M.end(); it++) {
      if (str1 == it->second) {
        it->second = str2;
        nofind = false;
        break;
      }
    }
    if (nofind) {
      M[str1] = str2;
      Num++;
    }
  }
}
void output() {
  cout << Num << endl;
  for (map<string, string>::iterator it = M.begin(); it != M.end(); it++) {
    cout << it->first << " " << it->second << endl;
  }
}
