#include <bits/stdc++.h>
using namespace std;
map<string, string> mp, track;
map<string, int> mark;
vector<string> parent;
string origin(string n) {
  if (mp[n] == "NULL") return n;
  return mp[n] = origin(mp[n]);
}
int main() {
  int n, i;
  string a, b, r;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> a >> b;
    if (mp[a].empty()) mp[a] = "NULL";
    mp[b] = a;
    r = origin(a);
    if (r == a) {
      if (!mark[a]) parent.push_back(a);
      mark[a] = 1;
    } else
      track[r] = a;
    r = origin(b);
    track[r] = b;
  }
  cout << parent.size() << endl;
  for (i = 0; i < parent.size(); i++) {
    cout << parent[i] << " " << track[parent[i]] << endl;
  }
}
