#include <bits/stdc++.h>
using namespace std;
int main() {
  map<string, int> m;
  map<int, string> mm;
  vector<int> v;
  int t;
  cin >> t;
  int cc = 0;
  int p[2000];
  while (t--) {
    string a, b;
    cin >> a >> b;
    if (!m[a]) {
      m[a] = ++cc;
      mm[cc] = a;
      v.push_back(cc);
    }
    if (!m[b]) {
      m[b] = ++cc;
      mm[cc] = b;
      p[cc] = cc;
    }
    p[m[a]] = m[b];
  }
  cout << (int)v.size() << endl;
  for (int i = 0; i < v.size(); i++) {
    cout << mm[v[i]] << " ";
    int cur = v[i];
    while (p[cur] != cur) {
      cur = p[cur];
    }
    cout << mm[cur] << "\n";
  }
}
