#include <bits/stdc++.h>
using namespace std;
int nextt[3000];
string s[3000];
bool ck[3000];
int main() {
  int N;
  cin >> N;
  map<string, int> mp;
  int cnt = 0;
  while (N--) {
    string s1, s2;
    cin >> s1 >> s2;
    if (mp.find(s1) == mp.end()) mp[s1] = ++cnt, s[cnt] = s1;
    if (mp.find(s2) == mp.end()) mp[s2] = ++cnt, s[cnt] = s2;
    nextt[mp[s1]] = mp[s2];
  }
  string ans;
  int res = 0;
  for (int i = 0; i < 3000; i++) {
    if (nextt[i] && !ck[i]) {
      int t = i;
      res++;
      ans += s[i] + " ";
      while (nextt[t] != 0) ck[t] = 1, t = nextt[t];
      ans += s[t] + "\n";
    }
  }
  cout << res << '\n';
  puts(ans.c_str());
}
