#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
    map<string, string> interpolate = { { "F", "a && b && c" }, { "H", "p ^ 2 + w" }, { "K", "H > 10 || e < 5" }, { "J", "F && !K" } };

    for(map<string, string>::iterator i = interpolate.begin(); i != interpolate.end(); ++i) {
        for(map<string, string>::iterator it = interpolate.begin(); it != interpolate.end(); ++it) {
            for(string::size_type pos = it->second.find(i->first); pos != string::npos; pos = it->second.find(i->first, pos)) {
                it->second.replace(pos, i->first.size(), '(' + i->second + ')');
            }
        }
    }
    
    for(map<string, string>::iterator i = interpolate.begin(); i != interpolate.end(); ++i) {
    	cout << i->first << " : " << i->second << endl;
    }
}