#include <bits/stdc++.h>
using namespace std;
int n;
map<string, string> handle;
map<string, string> curr_handle;
map<string, string>::iterator it;
int main() {
  cin >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    string a, b;
    cin >> a >> b;
    if (curr_handle.find(a) == curr_handle.end()) {
      ans++;
      handle[a] = b;
      curr_handle[b] = a;
    } else {
      handle[curr_handle[a]] = b;
      curr_handle[b] = curr_handle[a];
      curr_handle.erase(curr_handle[a]);
    }
  }
  cout << ans << endl;
  it = handle.begin();
  while (it != handle.end()) {
    cout << it->first << " " << it->second << endl;
    it++;
  }
}
