#include <bits/stdc++.h>   using namespace std;   struct Widget {     string type, name;     vector<Widget *> childs;     long long h, w, s, b;     Widget(string _name =   , string _type =   , long long _h = -1,            long long _w = -1) {       h = _h, w = _w;       type = _type;       name = _name;       s = 0;       b = 0;     }     void pack(Widget *W) { childs.push_back(W); }     long long getW() {       if (type ==  normal )         return w;       else if (type ==  VBox ) {         if (childs.size() == 0) return 0;         if (w != -1) return w;         w = 0;         for (int i = 0; i < childs.size(); ++i) w = max(w, childs[i]->getW());         return w = w + 2 * b;       } else {         if (childs.size() == 0) return 0;         if (w != -1) return w;         w = 0;         for (int i = 0; i < childs.size(); ++i) w += childs[i]->getW();         return w = w + 2 * b + s * max(0LL, (long long)childs.size() - 1);       }     }     long long getH() {       if (type ==  normal )         return h;       else if (type ==  HBox ) {         if (childs.size() == 0) return 0;         if (h != -1) return h;         h = 0;         for (int i = 0; i < childs.size(); ++i) h = max(h, childs[i]->getH());         return h = h + 2 * b;       } else {         if (childs.size() == 0) return 0;         if (h != -1) return h;         h = 0;         for (int i = 0; i < childs.size(); ++i) h += childs[i]->getH();         return h = h + 2 * b + s * max(0LL, (long long)childs.size() - 1);       }     }   };   map<string, Widget> M;   int main() {     int N;     cin >> N;     for (int i = 0; i < N; ++i) {       string com;       cin >> com;       if (com ==  Widget ) {         string name;         cin >> name;         int p1 = name.find( ( );         int p2 = name.find( , );         int p3 = name.find( ) );         string rname = name.substr(0, p1);         string val1 = name.substr(p1 + 1, p2 - p1 - 1);         string val2 = name.substr(p2 + 1, p3 - p2 - 1);         int h, w;         sscanf((val1 +     + val2).c_str(),  %d %d , &w, &h);         M[rname] = Widget(name,  normal , h, w);       } else if (com ==  VBox  || com ==  HBox ) {         string name;         cin >> name;         M[name] = Widget(name, com);       } else {         string name, method, val;         int p1 = com.find( . );         int p2 = com.find( ( );         int p3 = com.find( ) );         name = com.substr(0, p1);         method = com.substr(p1 + 1, p2 - p1 - 1);         val = com.substr(p2 + 1, p3 - p2 - 1);         if (method ==  pack ) {           M[name].pack(&M[val]);         } else {           int n;           sscanf(val.c_str(),  %d , &n);           if (method ==  set_spacing )             M[name].s = n;           else             M[name].b = n;         }       }     }     for (map<string, Widget>::iterator it = M.begin(); it != M.end(); ++it)       cout << (it->first) <<     << (it->second.getW()) <<                << (it->second.getH()) << endl;   }   