#include <bits/stdc++.h>   namespace algo {   using namespace std;   const long double PI = 3.141592653589793238462643383279502884L;   const long double E = 2.718281828459045235360287471352662498L;   const long double EPS = 1e-12L;   template <typename T1, typename T2>   T1 bin_pow(T1 a, T2 n) {     T1 r = 1;     while (n > 0) {       if (n & 1) r *= a;       a *= a;       n /= 2;     }     return r;   }   template <typename T1, typename T2>   T1 bin_pow(T1 a, T2 n, const T1& m) {     if (m == 1) return 0;     T1 r = 1;     while (n > 0) {       if (n & 1) {         r *= a;         r %= m;       }       a *= a;       a %= m;       n /= 2;     }     return r;   }   template <typename T>   T gcd(const T& a, const T& b) {     if (b == 0) return abs(a);     return gcd(b, a % b);   }   template <typename T>   T gcd(const T& a, const T& b, T& x, T& y) {     if (b == 0) {       x = a < 0 ? -1 : 1;       y = 0;       return x * a;     }     T d = gcd(b, a % b, y, x);     y -= (a / b) * x;     return d;   }   template <typename T>   T lcm(const T& a, const T& b) {     return abs(a / gcd(a, b) * b);   }   template <typename T>   T mod_add(const T& a, const T& b, const T& m) {     if (a < m - b) return a + b;     return a - (m - b);   }   template <typename T>   T mod_sub(const T& a, const T& b, const T& m) {     if (a < b) return a + (m - b);     return a - b;   }   template <typename T>   T mod_mul(T a, T b, const T& m) {     if (b > a) swap(a, b);     T r = 0;     while (b > 0) {       if (b & 1) r = mod_add(r, a, m);       a = mod_add(a, a, m);       b /= 2;     }     return r;   }   template <typename T1, typename T2>   T1 mod_pow(T1 a, T2 n, const T1& m) {     if (m == 1) return 0;     T1 r = 1;     while (n > 0) {       if (n & 1) r = mod_mul(r, a, m);       a = mod_mul(a, a, m);       n /= 2;     }     return r;   }   template <typename T>   T mod_inv(const T& a, const T& m) {     T x, y;     T d = gcd(a, m, x, y);     if (d != 1) return 0;     if (x < 0) x += m;     return x;   }   struct Sieve {     int* lpf = nullptr;     int* phi = nullptr;     int size;     vector<int> primes;     Sieve(bool calcPhi = false, int n = 0xfffff) : size(n) {       lpf = new int[size + 1];       fill(lpf, lpf + size + 1, 0);       lpf[1] = 1;       if (calcPhi) {         phi = new int[size + 1];         phi[1] = 1;         for (int i = 2; i <= size; ++i) {           if (lpf[i] == 0) {             phi[i] = i - 1;             lpf[i] = i;             primes.push_back(i);           }           for (int j = 0, t; j < primes.size() && (t = i * primes[j]) <= size;                ++j) {             lpf[t] = primes[j];             if (primes[j] == lpf[i]) {               phi[t] = phi[i] * primes[j];               break;             }             phi[t] = phi[i] * (primes[j] - 1);           }         }       } else {         for (int i = 2; i <= size; ++i) {           if (lpf[i] == 0) {             lpf[i] = i;             primes.push_back(i);           }           for (int j = 0, t; j < primes.size() && (t = i * primes[j]) <= size;                ++j) {             lpf[t] = primes[j];             if (primes[j] == lpf[i]) break;           }         }       }     }     Sieve(int n) : Sieve(false, n) {}     ~Sieve() {       delete[] lpf;       lpf = nullptr;       delete[] phi;       phi = nullptr;     }   };   template <typename T>   T phi(T n) {     T r = n;     for (T i = 2; i * i <= n; ++i) {       if (n % i == 0) {         r -= r / i;         do {           n /= i;         } while (n % i == 0);       }     }     if (n > 1) r -= r / n;     return r;   }   }  // namespace algo   using namespace std;   using namespace algo;   namespace task {   struct Widget;   map<string, Widget*> widgets;   struct Widget {     char type;     int64_t width = -1;     int64_t height = -1;     int64_t border = 0;     int64_t spacing = 0;     vector<string> children;     Widget(char type, int64_t width = -1, int64_t height = -1)         : type(type), width(width), height(height) {}     void pack(const string& name) { children.push_back(name); }     pair<int64_t, int64_t> size() {       if (width == -1 || height == -1) {         if (type ==  W ) {           exit(3);         } else if (children.size() == 0) {           width = 0;           height = 0;         } else if (type ==  H ) {           int64_t t_width = (children.size() - 1) * spacing;           int64_t t_height = 0;           for (int i = 0; i < children.size(); ++i) {             pair<int64_t, int64_t> t_size = widgets[children[i]]->size();             t_width += t_size.first;             t_height = max(t_height, t_size.second);           }           width = t_width + 2 * border;           height = t_height + 2 * border;         } else if (type ==  V ) {           int64_t t_width = 0;           int64_t t_height = (children.size() - 1) * spacing;           for (int i = 0; i < children.size(); ++i) {             pair<int64_t, int64_t> t_size = widgets[children[i]]->size();             t_width = max(t_width, t_size.first);             t_height += t_size.second;           }           width = t_width + 2 * border;           height = t_height + 2 * border;         }       }       return {width, height};     }   };   int n, x, y;   string s, name1, name2;   int main() {     cin >> n;     for (int i = 0; i < n; ++i) {       cin >> s;       if (s ==  Widget ) {         cin >> s;         char name[16];         int64_t width, height;         sscanf(s.c_str(),  %[a-z](%lli,%lli) , name, &width, &height);         name1 = string(name);         widgets[name1] = new Widget( W , width, height);       } else if (s ==  VBox ) {         cin >> name1;         widgets[name1] = new Widget( V );       } else if (s ==  HBox ) {         cin >> name1;         widgets[name1] = new Widget( H );       } else {         char name_1[16];         char name_2[16];         char method[16];         sscanf(s.c_str(),  %[a-z].%[a-z_](%[a-z0-9]) , name_1, method, name_2);         name1 = string(name_1);         if (string(method) ==  pack ) {           name2 = string(name_2);           widgets[name1]->pack(name2);         } else if (string(method) ==  set_border ) {           int64_t border;           sscanf(name_2,  %lli , &border);           widgets[name1]->border = border;         } else if (string(method) ==  set_spacing ) {           int64_t spacing;           sscanf(name_2,  %lli , &spacing);           widgets[name1]->spacing = spacing;         }       }     }     for (auto& it : widgets) {       pair<int64_t, int64_t> size = it.second->size();       cout << it.first <<     << size.first <<     << size.second <<   n ;     }     return 0;   }   }  // namespace task   int main() {     ios_base::sync_with_stdio(false);     cin.tie(nullptr);     cout.precision(11);     cout.setf(ios::fixed);     return task::main();   }