#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
bool oq = false;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  map<string, string> handles;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string old, nw;
    cin >> old;
    cin >> nw;
    while (handles.find(old) != handles.end()) {
      string prev = old;
      old = handles[old];
      handles.erase(prev);
    }
    handles[nw] = old;
  }
  cout << handles.size() << endl;
  for (auto x : handles) cout << x.second << " " << x.first << endl;
}
