#include <bits/stdc++.h>
using namespace std;
string keep_root(map<string, string> mp, string str) {
  while (mp.at(str) != str) {
    str = mp.at(str);
  }
  return str;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int q, c = 0;
  cin >> q;
  map<string, string> mp;
  vector<int> v;
  set<string> st;
  while (q--) {
    string o, n;
    cin >> o >> n;
    if (st.find(o) == st.end()) {
      mp[o] = o;
      mp[n] = o;
      c++;
    } else {
      string root = keep_root(mp, o);
      mp[n] = root;
      mp.erase(o);
    }
    st.insert(n);
  }
  cout << c << "\n";
  for (auto it = mp.begin(); it != mp.end(); it++) {
    if (it->second != it->first) cout << it->second << " " << it->first << "\n";
  }
  return 0;
}
