#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  map<string, string> A;
  int n;
  string a, b;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    map<string, string>::iterator f = A.find(a);
    if (f == A.end()) {
      A[b] = a;
    } else {
      pair<string, string> n = pair<string, string>(b, f->second);
      A.erase(f);
      A.insert(n);
    }
  }
  cout << A.size() << endl;
  for (map<string, string>::iterator i = A.begin(); i != A.end(); i++) {
    cout << i->second << " " << i->first << endl;
  }
}
