#include <bits/stdc++.h>
using namespace std;
map<string, string> m;
int main() {
  int q, i, a;
  string s1, s2;
  map<string, string>::iterator it;
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    cin >> s1 >> s2;
    a = m.count(s1);
    if (!a) m[s1] = s1;
    m[s2] = m[s1];
    m.erase(s1);
  }
  printf("%d\n", m.size());
  for (it = m.begin(); it != m.end(); it++) {
    cout << it->second << " " << it->first << "\n";
  }
  return 0;
}
