#include <bits/stdc++.h>
using namespace std;
int curId;
int totalAddedCount[103][103], isHbox[103], isVbox[103], vis[103][103],
    graph[103][103], graphCnt[103];
struct trie {
  int widgetId, endMark;
  trie* next[26];
  trie() {
    widgetId = 0;
    endMark = 0;
    for (int i = 0; i < 26; i++) {
      next[i] = nullptr;
    }
  }
};
void trieInsert(trie* cur, string str, int currentId) {
  for (int i = 0; i < str.size(); i++) {
    int now = str[i] - 'a';
    if (cur->next[now] == nullptr) {
      cur->next[now] = new trie();
    }
    cur = cur->next[now];
  }
  cur->widgetId = currentId;
}
int trieSearch(trie* cur, string str, int type) {
  for (int i = 0; i < str.size(); i++) {
    int now = str[i] - 'a';
    if (cur->next[now] != nullptr) {
      cur = cur->next[now];
    } else {
      return 0;
    }
  }
  if (type == 1) {
  }
  return cur->widgetId;
}
struct Widget {
  string name, type;
  int id;
  long long int border, spacing, x, y, tot;
  Widget() {
    name = "";
    type = "";
    id = 0;
    border = 0;
    spacing = 0;
    x = 0;
    y = 0;
    tot = 0;
  }
};
Widget widget[103];
long long int convertToInt(string str) {
  long long int num = 0;
  for (int i = 0; i < str.size(); i++) {
    num = (num * 10) + (long long int)(str[i] - '0');
  }
  return num;
}
void setWidget(string name, int wid, int wx, int wy, string wtype) {
  widget[wid].name = name;
  widget[wid].id = wid;
  widget[wid].spacing = 0;
  widget[wid].border = 0;
  widget[wid].x = wx;
  widget[wid].y = wy;
  widget[wid].tot = 0;
  widget[wid].type = wtype;
}
void updateBorder(int wid, long long int wborder) {
  widget[wid].border = wborder;
}
void updateSpacing(int wid, long long int wspacing) {
  widget[wid].spacing = wspacing;
}
void clearAll() {
  for (int i = 0; i < 103; i++) {
    isHbox[i] = 0;
    isVbox[i] = 0;
    for (int j = 0; j < 103; j++) {
      totalAddedCount[i][j] = 0;
    }
  }
}
void dfs(int cur, int pre) {
  vis[pre][cur] = 1;
  for (int i = 0; i < graphCnt[cur]; i++) {
    int now = graph[cur][i];
    if (!vis[cur][now]) {
      dfs(now, cur);
    }
  }
  if (pre != 0) {
    widget[pre].tot += totalAddedCount[pre][cur];
    if (graphCnt[cur] == 0) {
      if (isHbox[cur] || isVbox[cur]) {
        updateBorder(cur, 0);
        updateSpacing(cur, 0);
        widget[cur].x = 0;
        widget[cur].y = 0;
      }
    } else {
      if (isHbox[cur]) {
        if (widget[cur].tot > 0)
          widget[cur].x += (widget[cur].tot - 1) * widget[cur].spacing;
        widget[cur].tot = 0;
      } else if (isVbox[cur]) {
        if (widget[cur].tot > 0)
          widget[cur].y += (widget[cur].tot - 1) * widget[cur].spacing;
        widget[cur].tot = 0;
      }
      widget[cur].x += widget[cur].border * 2;
      widget[cur].y += widget[cur].border * 2;
      widget[cur].border = 0;
    }
    if (isHbox[pre]) {
      widget[pre].x += (widget[cur].x * totalAddedCount[pre][cur]);
      widget[pre].y = max(widget[pre].y, widget[cur].y);
    } else if (isVbox[pre]) {
      widget[pre].x = max(widget[pre].x, widget[cur].x);
      widget[pre].y += (widget[cur].y * totalAddedCount[pre][cur]);
    }
  } else {
    if (graphCnt[cur] == 0) {
      if (isHbox[cur] || isVbox[cur]) {
        updateBorder(cur, 0);
        updateSpacing(cur, 0);
        widget[cur].x = 0;
        widget[cur].y = 0;
      }
    } else {
      if (isHbox[cur]) {
        if (widget[cur].tot > 0)
          widget[cur].x += (widget[cur].tot - 1) * widget[cur].spacing;
        widget[cur].tot = 0;
      } else if (isVbox[cur]) {
        if (widget[cur].tot > 0)
          widget[cur].y += (widget[cur].tot - 1) * widget[cur].spacing;
        widget[cur].tot = 0;
      }
      widget[cur].x += widget[cur].border * 2;
      widget[cur].y += widget[cur].border * 2;
      widget[cur].border = 0;
    }
  }
}
int main() {
  int n;
  string inp;
  cin >> n;
  cin.ignore();
  curId = 0;
  clearAll();
  trie* trieRoot = new trie();
  for (int i = 0; i < n; i++) {
    getline(cin, inp);
    if (inp[0] == 'W') {
      int j = 7;
      string name = "", curx = "", cury = "";
      while (inp[j] != '(') {
        name += inp[j];
        j++;
      }
      j++;
      while (inp[j] != ',') {
        curx += inp[j];
        j++;
      }
      j++;
      while (inp[j] != ')') {
        cury += inp[j];
        j++;
      }
      long long int curxx = convertToInt(curx);
      long long int curyy = convertToInt(cury);
      if (trieSearch(trieRoot, name, 0) == 0) {
        trieInsert(trieRoot, name, ++curId);
      }
      setWidget(name, trieSearch(trieRoot, name, 0), curxx, curyy, "none");
    } else if (inp[0] == 'H') {
      int j = 5;
      string name = "";
      while (j < inp.size()) {
        name += inp[j];
        j++;
      }
      if (trieSearch(trieRoot, name, 0) == 0) {
        trieInsert(trieRoot, name, ++curId);
      }
      int getId = trieSearch(trieRoot, name, 0);
      isHbox[getId] = 1;
      setWidget(name, getId, 0, 0, "hbox");
    } else if (inp[0] == 'V') {
      int j = 5;
      string name = "";
      while (j < inp.size()) {
        name += inp[j];
        j++;
      }
      if (trieSearch(trieRoot, name, 0) == 0) {
        trieInsert(trieRoot, name, ++curId);
      }
      int getId = trieSearch(trieRoot, name, 0);
      isVbox[getId] = 1;
      setWidget(name, getId, 0, 0, "vbox");
    } else {
      int j = 0;
      while (inp[j] != '.') j++;
      if (inp[j + 1] == 'p') {
        int j = 0;
        string fname = "", sname = "";
        while (inp[j] != '.') {
          fname += inp[j];
          j++;
        }
        while (inp[j] != '(') j++;
        j++;
        while (inp[j] != ')') {
          sname += inp[j];
          j++;
        }
        int fId = trieSearch(trieRoot, fname, 0);
        int sId = trieSearch(trieRoot, sname, 0);
        if (totalAddedCount[fId][sId] == 0) {
          graph[fId][graphCnt[fId]++] = sId;
        }
        totalAddedCount[fId][sId]++;
      } else {
        while (inp[j] != '_') j++;
        if (inp[j + 1] == 'b') {
          string name = "", borderStr = "";
          int j = 0;
          while (inp[j] != '.') name += inp[j], j++;
          j++;
          while (inp[j] != '(') j++;
          j++;
          while (inp[j] != ')') {
            borderStr += inp[j];
            j++;
          }
          long long int borderInt = convertToInt(borderStr);
          updateBorder(trieSearch(trieRoot, name, 0), borderInt);
        } else if (inp[j + 1] == 's') {
          string name = "", spaceStr = "";
          int j = 0;
          while (inp[j] != '.') name += inp[j], j++;
          j++;
          while (inp[j] != '(') j++;
          j++;
          while (inp[j] != ')') {
            spaceStr += inp[j];
            j++;
          }
          long long int spaceInt = convertToInt(spaceStr);
          updateSpacing(trieSearch(trieRoot, name, 0), spaceInt);
        }
      }
    }
  }
  for (int i = 1; i <= curId; i++) {
    if (isHbox[i] || isVbox[i]) {
      dfs(i, 0);
    }
  }
  vector<string> allName;
  for (int i = 1; i <= curId; i++) {
    allName.push_back(widget[i].name);
  }
  sort(allName.begin(), allName.end());
  for (int i = 0; i < curId; i++) {
    int nowId = trieSearch(trieRoot, allName[i], 0);
    cout << allName[i] << " " << widget[nowId].x << " " << widget[nowId].y
         << endl;
  }
  return 0;
}
