#include <bits/stdc++.h>
using namespace std;
int main() {
  long long q;
  cin >> q;
  string s1, s2;
  map<string, string> m;
  map<string, string>::iterator it;
  for (int i = 0; i < q; i++) {
    cin >> s1 >> s2;
    bool k = 0;
    for (it = m.begin(); it != m.end(); it++) {
      if (it->second == s1) {
        m[it->first] = s2;
        k = 1;
        break;
      }
    }
    if (k == 0) m.insert({s1, s2});
  }
  cout << m.size() << endl;
  for (it = m.begin(); it != m.end(); it++) {
    cout << it->first << ' ' << it->second << endl;
  }
}
