#include <bits/stdc++.h>   using namespace std;   map<string, string> p;   map<string, string>::iterator it = p.begin();   int main() {     int q;     cin >> q;     while (q--) {       string s1, s2;       cin >> s1 >> s2;       if (!p.count(s1))         p[s2] = s1;       else {         p[s2] = p[s1];         p.erase(s1);       }     }     cout << p.size() << endl;     for (it = p.begin(); it != p.end(); it++)       cout << it->second <<     << it->first << endl;     return 0;   }   