#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 9, mod = 1e9 + 7, inf = 1e17;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  map<string, string> old;
  map<string, string> ne;
  string s, t;
  for (int i = 0; i < n; i++) {
    cin >> s >> t;
    if (ne[s].empty()) {
      old[s] = t;
      ne[t] = s;
    } else {
      old[ne[s]] = t;
      ne[t] = ne[s];
    }
  }
  cout << old.size() << "\n";
  for (auto el : old) cout << el.first << " " << el.second << "\n";
}
