#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<string, string> mp;
  set<string> s;
  for (int i = 0; i < n; i++) {
    string old, edg;
    cin >> old >> edg;
    mp[old] = edg;
    s.insert(edg);
  }
  map<string, string>::iterator p;
  p = mp.begin();
  vector<pair<string, string>> a;
  for (p; p != mp.end(); p++) {
    if (s.count(p->first)) continue;
    string cur;
    cur = p->first;
    while (mp.count(cur)) {
      cur = mp[cur];
    }
    a.push_back(make_pair(p->first, cur));
  }
  cout << a.size() << "\n";
  for (int i = 0; i < a.size(); i++)
    cout << a[i].first << " " << a[i].second << "\n";
}
