#include <bits/stdc++.h>
using namespace std;
int n, k;
string s1, s2;
vector<pair<string, string> > ans;
map<string, int> u;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s1 >> s2;
    map<string, int>::iterator it = u.find(s1);
    if (it == u.end()) {
      u[s1] = k, u[s2] = k;
      ans.push_back(make_pair(s1, s2));
      k++;
    } else {
      u[s2] = it->second;
      ans[it->second].second = s2;
    }
  }
  cout << ans.size() << endl;
  for (size_t i = 0; i < ans.size(); i++) {
    cout << ans[i].first << " " << ans[i].second << endl;
  }
  return 0;
}
