#include <bits/stdc++.h>
using namespace std;
int main() {
  string s1, s2, s;
  long long int n;
  scanf("%I64d", &n);
  map<string, string> mp;
  vector<string> v;
  vector<pair<string, string> > vans;
  map<string, string>::iterator it, iit;
  for (long long int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    mp[s1] = s2;
    v.push_back(s1);
  }
  for (long long int i = 0; i < n; i++) {
    if (mp[v[i]] != "") {
      s = v[i];
      while (mp[s] != "") {
        s1 = s;
        s = mp[s];
        iit = mp.find(s1);
        mp.erase(iit);
      }
      vans.push_back(make_pair(v[i], s));
    }
  }
  cout << vans.size() << endl;
  for (long long int i = 0; i < vans.size(); i++) {
    cout << vans[i].first << " " << vans[i].second << endl;
  }
}
