#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
int upmin(T1 &x, T2 v) {
  if (x <= v) {
    return 0;
  }
  x = v;
  return 1;
}
template <class T1, class T2>
int upmax(T1 &x, T2 v) {
  if (x >= v) {
    return 0;
  }
  x = v;
  return 1;
}
const int INF = 0x3f3f3f3f;
void init() {
  int N;
  cin >> N;
  map<string, string> mp, rvmp;
  for (int i = 0; i < N; ++i) {
    string a, b;
    cin >> a >> b;
    if (not rvmp.count(a)) {
      mp[a] = b;
      rvmp[b] = a;
    } else {
      mp[rvmp[a]] = b;
      rvmp[b] = rvmp[a];
      rvmp.erase(a);
    }
  }
  cout << mp.size() << endl;
  for (auto it = mp.begin(); it != mp.end(); ++it) {
    cout << it->first << " " << it->second << endl;
  }
}
void preprocess() {}
void solve() {}
signed main() {
  ios::sync_with_stdio(0);
  init();
  preprocess();
  solve();
  return 0;
}
