#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
const double eps = 1e-5;
map<string, string> mp;
map<string, int> mp2;
vector<string> ans;
int main() {
  int q;
  string s1, s2;
  scanf("%d", &q);
  int num = 0;
  for (int i = 1; i <= q; i++) {
    cin >> s1 >> s2;
    if (!mp2[s1]) {
      ans.push_back(s1);
      mp[s1] = s2;
      mp[s2] = s1;
      num++;
    } else {
      mp[mp[s1]] = s2;
      mp[s2] = mp[s1];
    }
    mp2[s2] = 1;
  }
  printf("%d\n", num);
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " " << mp[ans[i]] << endl;
  }
  return 0;
}
