#include <bits/stdc++.h>
using namespace std;
int main() {
  int num;
  vector<pair<string, string>> A;
  vector<pair<string, string>> newone;
  string s1, s2;
  cin >> num;
  for (int i = 0; i < num; i++) {
    cin >> s1;
    cin >> s2;
    pair<string, string> p(s1, s2);
    A.push_back(p);
  }
  int size = A.size();
  for (int i = 0; i < size; i++) {
    pair<string, string> temp(A[i].first, A[i].second);
    for (int j = i; j < size; j++) {
      if (temp.second == A[j].first) {
        temp.second = A[j].second;
        A[j].first = "NULL";
      }
    }
    if (temp.first != "NULL") newone.push_back(temp);
  }
  cout << newone.size() << endl;
  for (int i = 0; i < newone.size(); i++) {
    cout << newone[i].first << " " << newone[i].second << endl;
  }
}
