#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<pair<string, string> > p;
  string s1, s2;
  int i, j, n;
  bool t;
  cin >> n;
  for (i = 1; i <= n; i++) {
    t = true;
    cin >> s1 >> s2;
    for (j = 0; j < p.size(); j++) {
      if (p[j].second == s1) {
        t = false;
        p[j].second = s2;
        break;
      }
    }
    if (t) {
      p.push_back({s1, s2});
    }
  }
  cout << p.size() << endl;
  for (j = 0; j < p.size(); j++)
    cout << p[j].first << " " << p[j].second << endl;
  return 0;
}
