#include <bits/stdc++.h>   using namespace std;   unordered_set<string> has_handle;   unordered_set<string> is_new;   unordered_map<string, string> handle;   vector<string> handles_new;   vector<string> handles_old;   void solve(string old) {     if (is_new.count(old)) return;     handles_old.push_back(old);     string temp;     while (true) {       temp = handle[old];       if (has_handle.count(temp) == 0) break;       old = temp;     }     handles_new.push_back(temp);   }   int main() {     int q;     cin >> q;     string old_handle[q], new_handle[q];     for (int i = 0; i < q; i++) {       cin >> old_handle[i] >> new_handle[i];       has_handle.insert(old_handle[i]);       is_new.insert(new_handle[i]);       handle[old_handle[i]] = new_handle[i];     }     for (int i = 0; i < q; i++) solve(old_handle[i]);     int cnt = handles_new.size();     cout << cnt << endl;     for (int i = 0; i < cnt; i++)       cout << handles_old[i] <<     << handles_new[i] << endl;     return 0;   }   