#include <bits/stdc++.h>
using namespace std;
map<string, string> handles;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string _new, old;
    cin >> _new >> old;
    string key = "";
    for (auto x : handles) {
      if (x.second == _new) {
        key = x.first;
      }
    }
    if (key == "") {
      handles[_new] = old;
    } else {
      handles[key] = old;
    }
  }
  cout << handles.size() << '\n';
  for (auto x : handles) {
    cout << x.first << ' ' << x.second << '\n';
  }
}
