#include <bits/stdc++.h>   using namespace std;   const double pi = acos(-1.0);   const double eps = 1e-11;   const int inf = 0x7FFFFFFF;   template <class T>   inline void checkmin(T &a, T b) {     if (b < a) a = b;   }   template <class T>   inline void checkmax(T &a, T b) {     if (b > a) a = b;   }   template <class T>   inline T sqr(T x) {     return x * x;   }   template <class T>   void show(T a, int n) {     for (int i = 0; i < n; ++i) cout << a[i] <<    ;     cout << endl;   }   template <class T>   void show(T a, int r, int l) {     for (int i = 0; i < r; ++i) show(a[i], l);     cout << endl;   }   struct S {     long long w, h;     long long bord, space;     string tp;     vector<int> son;     int vis;     void init(int x, int y, string t) {       w = x, h = y;       bord = space = 0;       tp = t;       son.clear();       vis = false;     }     void dfs();   } s[100000];   char buf[10000];   void S::dfs() {     vis = true;     if (son.size() > 0) {       for (int i = 0; i < son.size(); i++)         if (!s[son[i]].vis) {           s[son[i]].dfs();         }       if (tp ==  VBox ) {         for (int i = 0; i < son.size(); i++) {           int v = son[i];           w = max(s[v].w, w);           if (i > 0) h += space;           h += s[v].h;         }         w += 2 * bord;         h += 2 * bord;       } else if (tp ==  HBox ) {         for (int i = 0; i < son.size(); i++) {           int v = son[i];           h = max(s[v].h, h);           if (i > 0) w += space;           w += s[v].w;         }         w += 2 * bord;         h += bord * 2;       }     }   }   string nn[10000];   struct SS {     string s;     long long x, y;     const bool operator<(const SS &b) const { return s < b.s; }   } ss[10000];   int main() {     int n;     while (cin >> n) {       map<string, int> mp;       int cnt = 0;       for (int i = 0; i < n; i++) {         scanf(  %[^ n] , buf);         bool newtp = true;         for (int i = 0; buf[i]; i++)           if (buf[i] ==  (  || buf[i] ==  )  || buf[i] ==  .  || buf[i] ==  , ) {             if (buf[i] ==  . ) newtp = false;             buf[i] =    ;           }         istringstream sin(buf);         string t, nm, nm2;         sin >> t;         if (t ==  Widget  || t ==  VBox  || t ==  HBox ) {           int x = 0, y = 0;           sin >> nm;           mp[nm] = cnt;           nn[cnt] = nm;           if (t ==  Widget ) {             sin >> x >> y;           }           s[cnt].init(x, y, t);           cnt++;         } else {           nm = t;           int x;           sin >> t;           if (t ==  set_border ) {             sin >> x;             s[mp[nm]].bord = x;           } else if (t ==  set_spacing ) {             sin >> x;             s[mp[nm]].space = x;           } else if (t ==  pack ) {             sin >> nm2;             s[mp[nm]].son.push_back(mp[nm2]);           } else             puts( fuck );         }       }       for (int i = 0; i < cnt; i++) {         if (!s[i].vis) s[i].dfs();       }       for (int i = 0; i < cnt; i++) {         ss[i].s = nn[i];         ss[i].x = s[i].w;         ss[i].y = s[i].h;       }       sort(ss, ss + cnt);       for (int i = 0; i < cnt; i++) {         cout << ss[i].s <<     << ss[i].x <<     << ss[i].y << endl;       }     }     return 0;   }