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