#include <bits/stdc++.h>
using namespace std;
int n;
string f, s;
map<string, string> mp;
map<string, bool> used;
deque<string> V, D;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> f >> s;
    if (!used[f]) {
      mp[f] = f;
      V.push_back(f);
    }
    used[s] = 1;
    mp[s] = mp[f];
    D.push_back(s);
  }
  cout << V.size() << endl;
  for (int i = 0; i < V.size(); i++) {
    for (int j = D.size() - 1; j >= 0; j--) {
      if (mp[D[j]] == V[i]) {
        cout << V[i] << " " << D[j] << endl;
        break;
      }
    }
  }
}
