#include <bits/stdc++.h>
using namespace std;
map<string, string> m;
map<string, int> used;
string f(string x) {
  used[x] = 1;
  if (m[x] == x) return x;
  return f(m[x]);
}
int main() {
  int count = 0;
  vector<string> tab;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string p1, p2;
    cin >> p1 >> p2;
    if (m[p1].empty()) {
      ++count;
      tab.push_back(p1);
    }
    used[p1] = 0;
    used[p2] = 0;
    m[p1] = p2;
    m[p2] = p2;
  }
  cout << count << endl;
  for (int i = 0; i < count; ++i) {
    if (used[tab[i]] == 1) continue;
    cout << tab[i] << " " << f(tab[i]) << endl;
  }
  return 0;
}
