#include <bits/stdc++.h>
using namespace std;
void c_p_c() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  c_p_c();
  long int i, n;
  vector<pair<string, string>> v;
  string s1, s2;
  while (cin >> n) {
    while (n--) {
      cin >> s1 >> s2;
      for (i = 0; i < v.size(); i++) {
        if (v[i].second == s1) {
          v[i].second = s2;
          break;
        }
      }
      if (i == v.size()) {
        v.push_back(make_pair(s1, s2));
      }
    }
    cout << v.size() << '\n';
    for (i = 0; i < v.size(); i++) {
      cout << v[i].first << " " << v[i].second << '\n';
    }
  }
  return 0;
}
