#include <bits/stdc++.h>
using namespace std;
const int siz = 1e6 + 5;
const int MOD = 1e9 + 7;
void solve() {
  int q;
  cin >> q;
  string a[q], b[q];
  int i = 0;
  unordered_map<string, string> check, check1;
  while (q--) {
    bool flag = false;
    cin >> a[i] >> b[i];
    for (auto it : check) {
      if (it.second == a[i]) {
        string s = it.first;
        check.erase(it.first);
        check[s] = b[i];
        flag = true;
        break;
      }
    }
    if (!flag) {
      check[a[i]] = b[i];
    }
    i++;
  }
  cout << check.size() << '\n';
  for (auto it : check) cout << it.first << " " << it.second << '\n';
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
