#include <bits/stdc++.h>
using namespace std;
string s1[1005], s2[1005], p1, p2;
bool was[1005];
vector<pair<string, string> > ans;
void call(int i, int d) {
  int a, b, f = 0;
  was[i] = true;
  p1 = s2[i];
  for (a = i + 1; a <= d; a++) {
    if (s1[a] == p1) call(a, d);
  }
}
int main() {
  int a, b, c, d, f = 0;
  memset(was, 0, sizeof was);
  ans.clear();
  cin >> d;
  for (a = 1; a <= d; a++) {
    cin >> s1[a] >> s2[a];
  }
  for (a = 1; a <= d; a++) {
    if (was[a] == false) {
      f++;
      call(a, d);
      ans.push_back(make_pair(s1[a], p1));
    }
    was[a] = true;
  }
  cout << f << endl;
  for (a = 0; a < f; a++) cout << ans[a].first << " " << ans[a].second << endl;
  return 0;
}
