#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s1, s2;
  vector<pair<string, string>> lst;
  for (int i = 0; i < n; i++) {
    cin >> s1 >> s2;
    bool got = false;
    for (vector<pair<string, string>>::iterator it = lst.begin();
         it != lst.end(); it++) {
      if (it->second == s1) {
        it->second = s2;
        got = true;
        break;
      }
    }
    if (!got) lst.push_back(make_pair(s1, s2));
  }
  cout << lst.size() << endl;
  for (vector<pair<string, string>>::iterator it = lst.begin(); it != lst.end();
       it++) {
    cout << it->first << " " << it->second << endl;
  }
  return 0;
}
