#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5;
pair<string, string> hand[N];
map<string, string> par;
map<string, bool> seen;
string ans[N];
string dfs(string u) {
  seen[u] = true;
  if (par.count(u) == 0) return u;
  return dfs(par[u]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s, ss;
    cin >> s >> ss;
    hand[i] = {s, ss};
    par[s] = ss;
  }
  int m = 0;
  for (int i = 0; i < n; i++) {
    if (seen.count(hand[i].first) == 0) {
      string u = hand[i].first;
      while (par.count(u)) {
        u = par[u];
        seen[u] = true;
      }
      ans[m++] = hand[i].first + " " + u;
    }
  }
  cout << m << "\n";
  for (int i = 0; i < m; i++) cout << ans[i] << "\n";
}
