#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  int n, cnt = 0;
  vector<string> v;
  map<string, string> m, m1;
  scanf("%d", &n);
  while (n--) {
    cin >> a >> b;
    if (m.find(a) == m.end()) {
      m[b] = a;
      m1[a] = b;
      cnt++;
      v.push_back(a);
    } else {
      m[b] = m[a];
      m1[m[a]] = b;
    }
  }
  int len = v.size();
  cout << cnt << endl;
  for (int i = 0; i < len; i++) {
    cout << v[i] << " " << m1[v[i]] << endl;
  }
}
