#include <bits/stdc++.h>
using namespace std;
int n, fin[1300];
string oldname[1300], newname[1300];
int result[1300][3];
int res_x = 0;
int find_in_oldstring(int finding, int startsearch);
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) cin >> oldname[i] >> newname[i];
  for (int i = 1; i <= n; i++) {
    if (fin[i] == 0) {
      int where = i;
      while (true) {
        int prevwhere = where;
        where = find_in_oldstring(where, i + 1);
        if (where == 0) {
          result[++res_x][1] = i;
          result[res_x][2] = prevwhere;
          break;
        } else
          fin[where] = 1;
      }
      fin[i] = 1;
    }
  }
  cout << res_x << endl;
  for (int i = 1; i <= res_x; i++)
    cout << oldname[result[i][1]] << " " << newname[result[i][2]] << endl;
}
int find_in_oldstring(int finding, int startsearch) {
  string s = newname[finding];
  for (int i = startsearch; i <= n; i++) {
    if (s.compare(oldname[i]) == 0) return i;
  }
  return 0;
}
