#include <bits/stdc++.h>
using namespace std;
vector<pair<string, string>>::iterator findit(
    vector<pair<string, string>>::iterator st,
    vector<pair<string, string>>::iterator en, string s) {
  while (st != en) {
    if ((*st).second == s) {
      return st;
    } else {
      ++st;
    }
  }
  return en;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int q;
  cin >> q;
  string old, newi;
  long long int i;
  vector<pair<string, string>> v;
  long long int count = 0;
  for (i = 0; i < q; ++i) {
    cin >> old >> newi;
    vector<pair<string, string>>::iterator it = findit(v.begin(), v.end(), old);
    if (it == v.end()) {
      v.push_back(make_pair(old, newi));
      count++;
    } else {
      (*it).second = newi;
    }
  }
  cout << count << "\n";
  for (i = 0; i < count; ++i) {
    cout << v[i].first << " " << v[i].second << "\n";
  }
  return 0;
}
