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