#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int main() {
  std::ios::sync_with_stdio(false);
  map<string, string> m;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    string oldh, newh;
    cin >> oldh >> newh;
    if (m.find(oldh) == m.end()) {
      m[newh] = oldh;
    } else {
      m[newh] = m[oldh];
      m.erase(oldh);
    }
  }
  cout << m.size() << "\n";
  for (auto it : m) {
    cout << it.second << " " << it.first << "\n";
  }
  return 0;
}
