#include <bits/stdc++.h>
using namespace std;
map<string, string> m;
int main() {
  int n;
  cin >> n;
  string s1, s2;
  for (int i = 0; i < n; i++) {
    bool b = 1;
    cin >> s1 >> s2;
    if (!m.empty()) {
      for (auto a : m) {
        if (a.second == s1) {
          m[a.first] = s2;
          b = 0;
        }
      }
      if (b) m[s1] = s2;
    } else
      m[s1] = s2;
  }
  cout << m.size() << endl;
  for (auto a : m) cout << a.first << " " << a.second << endl;
}
