#include <bits/stdc++.h>   using namespace std;   map<string, int> m1;   map<int, string> m2;   pair<long long, long long> r[128];   long long H[128], V[128], B[128], S[128];   vector<int> g1[128], g2[128];   int G[128];   int main() {     memset(H, 0, sizeof H);     memset(V, 0, sizeof V);     memset(G, 0, sizeof G);     memset(B, 0, sizeof B);     memset(S, 0, sizeof S);     int N;     cin >> N;     string s;     getline(cin, s);     while (N--) {       getline(cin, s);       istringstream sin(s);       string s2;       sin >> s2;       if (s2 ==  Widget ) {         string name;         sin >> name;         name = name.substr(0, name.find( ( ) + 1);         istringstream sin2(s.substr(s.find( ( ) + 1));         int t1, t2;         char c;         sin2 >> t1 >> c >> t2;         name = name.substr(0, name.size() - 1);         int id = m1.size();         m1[name] = id;         m2[id] = name;         r[id] = make_pair(t1, t2);       } else if (s2 ==  VBox ) {         string name;         sin >> name;         int id = m1.size();         m1[name] = id;         m2[id] = name;         V[id] = 1;       } else if (s2 ==  HBox ) {         string name;         sin >> name;         int id = m1.size();         m1[name] = id;         m2[id] = name;         H[id] = 1;       } else if (s.find( set_border ) != string::npos) {         string name = s.substr(0, s.find( . ));         int id = m1[name];         istringstream sin2(s.substr(s.find( ( ) + 1));         int sz;         sin2 >> sz;         B[id] = sz;       } else if (s.find( set_spacing ) != string::npos) {         string name = s.substr(0, s.find( . ));         int id = m1[name];         istringstream sin2(s.substr(s.find( ( ) + 1));         int sz;         sin2 >> sz;         S[id] = sz;       } else if (s.find( pack ) != string::npos) {         string name1 = s.substr(0, s.find( . ));         string name2 = s.substr(s.find( ( ) + 1);         name2 = name2.substr(0, name2.size() - 1);         int id1 = m1[name1], id2 = m1[name2];         g1[id1].push_back(id2);         G[id1]++;         g2[id2].push_back(id1);       }     }     int left = m1.size();     int done[128];     memset(done, 0, sizeof done);     N = m1.size();     while (left) {       int cur = -1;       for (int i = 0; i < (N); i++)         if (done[i] == 0 && G[i] == 0) {           cur = i;         }       done[cur] = 1;       for (int i = 0; i < (g2[cur].size()); i++) G[g2[cur][i]]--;       left--;       long long x = 0, y = 0;       if (V[cur] && g1[cur].size()) {         for (int i = 0; i < (g1[cur].size()); i++) {           x = max(x, r[g1[cur][i]].first);           y += r[g1[cur][i]].second;         }         x += 2 * B[cur];         y += 2 * B[cur];         y += (g1[cur].size() - 1) * S[cur];         r[cur] = make_pair(x, y);       }       if (H[cur] && g1[cur].size()) {         for (int i = 0; i < (g1[cur].size()); i++) {           y = max(y, r[g1[cur][i]].second);           x += r[g1[cur][i]].first;         }         x += 2 * B[cur];         y += 2 * B[cur];         x += (g1[cur].size() - 1) * S[cur];         r[cur] = make_pair(x, y);       }     }     for (typeof(m1.begin()) it = m1.begin(); it != m1.end(); it++) {       cout << it->first <<     << r[it->second].first <<                << r[it->second].second << endl;     }     return 0;   }