#include <bits/stdc++.h>
using namespace std;
long long int ans;
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int q;
  cin >> q;
  string s1, s2;
  vector<vector<string>> v;
  while (q--) {
    cin >> s1 >> s2;
    int F = 0;
    for (int i = 0; i < v.size(); i++)
      if (s1 == v[i].back()) {
        v[i].back() = s2;
        F++;
        break;
      }
    if (F == 0) {
      vector<string> neW;
      neW.push_back(s1);
      neW.push_back(s2);
      v.push_back(neW);
    }
  }
  cout << v.size();
  cout << "\n";
  for (auto it : v) {
    for (string t : it) cout << t << " ";
    cout << "\n";
  }
  return 0;
}
