#include <bits/stdc++.h>
using namespace std;
long long n, i, j;
map<string, long long> m;
vector<pair<string, string> > v, v1;
string s, t, q;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s >> t;
    v.push_back(make_pair(s, t));
  }
  for (i = 0; i < n; i++) {
    if (m[v[i].first] == 0) {
      j = i + 1;
      q = v[i].second;
      while (j != n) {
        if (v[j].first == q && m[v[j].first] == 0) {
          q = v[j].second;
          m[v[j].first] = 1;
        }
        j++;
      }
      m[v[i].second] = 1;
      v1.push_back(make_pair(v[i].first, q));
    }
  }
  cout << v1.size() << endl;
  for (i = 0; i < v1.size(); i++) {
    cout << v1[i].first << " " << v1[i].second << endl;
  }
  return 0;
}
