#include <bits/stdc++.h>
using namespace std;
map<string, bool> used;
map<string, string> oldNew;
map<string, string> newOld;
int n;
string s1, s2;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    if (used[s2]) continue;
    if (used[s1]) {
      oldNew[newOld[s1]] = s2;
      used[s2] = 1;
      newOld[s2] = newOld[s1];
    } else {
      used[s1] = 1;
      used[s2] = 1;
      oldNew[s1] = s2;
      newOld[s2] = s1;
    }
  }
  cout << oldNew.size() << endl;
  for (map<string, string>::iterator it = oldNew.begin(); it != oldNew.end();
       ++it)
    cout << it->first << " " << it->second << '\n';
  return 0;
}
