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