#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int q;
  cin >> q;
  map<string, string> m;
  while (q--) {
    string a, b;
    cin >> a >> b;
    if (m.count(a)) {
      m[b] = m[a];
      m.erase(a);
    } else {
      m[b] = a;
    }
  }
  map<string, string>::iterator it = m.begin();
  cout << m.size() << endl;
  while (it != m.end()) {
    cout << it->second << " " << it->first << endl;
    it++;
  }
  return 0;
}
