#include <bits/stdc++.h>
using namespace std;
void oblivious() {
  long long int n;
  cin >> n;
  vector<pair<string, string> > v;
  for (long long int i = 0; i < n; i++) {
    string s1, s2;
    cin >> s1 >> s2;
    v.push_back(make_pair(s1, s2));
  }
  for (long long int i = 0; i < n; i++) {
    for (long long int j = i + 1; j < n; j++) {
      if (v[i].second == v[j].first) {
        v[i].second = v[j].second;
        v.erase(v.begin() + j);
        n--;
        j--;
      }
    }
  }
  auto it = v.begin();
  cout << n << endl;
  for (long long int i = 0; i < n; i++) {
    cout << v[i].first << " " << v[i].second << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  oblivious();
  return 0;
}
