#include <bits/stdc++.h>
using namespace std;
string s[1000][1000];
int main() {
  int n, res = 0;
  string a;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> s[i][0] >> s[i][1];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (s[i][0] == s[j][1]) {
        a = s[i][0];
        s[i][0] = s[j][0];
        s[j][0] = a;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (s[i][0] == s[i][1])
      continue;
    else
      res++;
  }
  cout << res << '\n';
  for (int i = 0; i < n; i++) {
    if (s[i][0] == s[i][1])
      continue;
    else
      cout << s[i][0] << " " << s[i][1] << '\n';
  }
  return 0;
}
