#include <bits/stdc++.h>
using namespace std;
int N;
char t1[25], t2[25];
string s1, s2, st;
map<string, int> all, first;
map<string, string> link;
int main() {
  scanf("%d", &N);
  while (N--) {
    scanf("%s %s", &t1, &t2);
    s1 = t1;
    s2 = t2;
    if (all.count(s1) == 0) {
      first[s1] = 1;
    }
    all[s1] = 1;
    all[s2] = 1;
    link[s1] = s2;
  }
  vector<string> v1, v2;
  for (map<string, int>::iterator it = first.begin(); it != first.end(); ++it) {
    v1.push_back((*it).first);
    string tmp = link[(*it).first];
    while (link.count(tmp)) {
      tmp = link[tmp];
    }
    v2.push_back(tmp);
  }
  printf("%lu\n", v1.size());
  for (int i = 0; i < v1.size(); ++i) {
    printf("%s %s\n", v1[i].c_str(), v2[i].c_str());
  }
}
