#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, string> a;
  map<string, string> b;
  map<string, string>::iterator it;
  string s1, s2;
  int n;
  scanf("%d", &n);
  int res = n;
  while (n--) {
    cin >> s1 >> s2;
    b[s2] = s1;
    if (b[s1] != "") res--;
    while (b[s1] != "") s1 = b[s1];
    a[s1] = s2;
  }
  printf("%d\n", res);
  for (it = a.begin(); it != a.end(); ++it) {
    cout << it->first << ' ' << it->second << endl;
  }
}
