#include <bits/stdc++.h>
int curId;
int totalAddedCount[103][103], isHbox[103], isVbox[103], vis[103][103],
    graph[103][103], graphCnt[103], sortedList[103], sortedListInd;
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, char str[23], int currentId) {
  for (int i = 0; str[i] != '\0'; i++) {
    int now = str[i] - 'a';
    if (cur->next[now] == nullptr) {
      cur->next[now] = new trie();
    }
    cur = cur->next[now];
  }
  cur->endMark = 1;
  cur->widgetId = currentId;
}
int trieSearch(trie *cur, char str[23], int type) {
  for (int i = 0; str[i] != '\0'; i++) {
    int now = str[i] - 'a';
    if (cur->next[now] != nullptr) {
      cur = cur->next[now];
    } else {
      return 0;
    }
  }
  return cur->widgetId;
}
void sortNameId(trie *cur) {
  if (cur == nullptr) return;
  if (cur->endMark == 1) {
    sortedList[sortedListInd++] = cur->widgetId;
  }
  for (int i = 0; i < 26; i++) {
    if (cur->next[i] != nullptr) {
      sortNameId(cur->next[i]);
    }
  }
}
struct Widget {
  char name[53], type[23];
  int id;
  long long int border, spacing, x, y, tot;
  Widget() {
    name[0] = '\0';
    type[0] = '\0';
    id = 0;
    border = 0;
    spacing = 0;
    x = 0;
    y = 0;
    tot = 0;
  }
};
Widget widget[103];
long long int convertToInt(char str[23]) {
  long long int num = 0;
  for (int i = 0; str[i] != '\0'; i++) {
    num = (num * 10) + (long long int)(str[i] - '0');
  }
  return num;
}
void setWidget(char name[53], int wid, int wx, int wy, char wtype[23]) {
  for (int i = 0; name[i] != '\0'; i++) widget[wid].name[i] = name[i];
  widget[wid].id = wid;
  widget[wid].spacing = 0;
  widget[wid].border = 0;
  widget[wid].x = wx;
  widget[wid].y = wy;
  widget[wid].tot = 0;
  for (int i = 0; wtype[i] != '\0'; i++) widget[wid].type[i] = wtype[i];
}
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;
    }
  }
}
long long int getMaximum(long long int fs, long long int sn) {
  if (fs >= sn) {
    return fs;
  }
  return sn;
}
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 = getMaximum(widget[pre].y, widget[cur].y);
    } else if (isVbox[pre]) {
      widget[pre].x = getMaximum(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;
  char inp[53];
  scanf("%d", &n);
  curId = 0;
  clearAll();
  trie *trieRoot = new trie();
  getchar();
  for (int i = 0; i < n; i++) {
    gets(inp);
    if (inp[0] == 'W') {
      int j = 7;
      char name[53], curx[23], cury[23];
      int nameId = 0, curxId = 0, curyId = 0;
      while (inp[j] != '(') {
        name[nameId] = inp[j];
        name[nameId + 1] = '\0';
        nameId++;
        j++;
      }
      j++;
      while (inp[j] != ',') {
        curx[curxId] = inp[j];
        curx[curxId + 1] = '\0';
        curxId++;
        j++;
      }
      j++;
      while (inp[j] != ')') {
        cury[curyId] = inp[j];
        cury[curyId + 1] = '\0';
        curyId++;
        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;
      char name[53];
      int nameInd = 0;
      while (inp[j] != '\0') {
        name[nameInd] = inp[j];
        name[nameInd + 1] = '\0';
        nameInd++;
        j++;
      }
      if (trieSearch(trieRoot, name, 0) == 0) {
        trieInsert(trieRoot, name, ++curId);
      }
      int getId = trieSearch(trieRoot, name, 0);
      isHbox[getId] = 1;
      char curType[23];
      curType[0] = 'h', curType[1] = 'b', curType[2] = '0', curType[3] = 'x';
      setWidget(name, getId, 0, 0, curType);
    } else if (inp[0] == 'V') {
      int j = 5;
      char name[53];
      int nameId = 0;
      while (inp[j] != '\0') {
        name[nameId] = inp[j];
        name[nameId + 1] = '\0';
        nameId++;
        j++;
      }
      if (trieSearch(trieRoot, name, 0) == 0) {
        trieInsert(trieRoot, name, ++curId);
      }
      int getId = trieSearch(trieRoot, name, 0);
      isVbox[getId] = 1;
      char curType[23];
      curType[0] = 'v', curType[1] = 'b', curType[2] = '0', curType[3] = 'x';
      setWidget(name, getId, 0, 0, curType);
    } else {
      int j = 0;
      while (inp[j] != '.') j++;
      if (inp[j + 1] == 'p') {
        int j = 0;
        char fname[23], sname[23];
        int fnameInd = 0, snameInd = 0;
        while (inp[j] != '.') {
          fname[fnameInd] = inp[j];
          fname[fnameInd + 1] = '\0';
          fnameInd++;
          j++;
        }
        while (inp[j] != '(') j++;
        j++;
        while (inp[j] != ')') {
          sname[snameInd] = inp[j];
          sname[snameInd + 1] = '\0';
          snameInd++;
          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') {
          char name[53], borderStr[23];
          int nameInd = 0, borderStrInd = 0;
          int j = 0;
          while (inp[j] != '.')
            name[nameInd] = inp[j], name[nameInd + 1] = '\0', nameInd++, j++;
          j++;
          while (inp[j] != '(') j++;
          j++;
          while (inp[j] != ')') {
            borderStr[borderStrInd] = inp[j];
            borderStr[borderStrInd + 1] = '\0';
            borderStrInd++;
            j++;
          }
          long long int borderInt = convertToInt(borderStr);
          updateBorder(trieSearch(trieRoot, name, 0), borderInt);
        } else if (inp[j + 1] == 's') {
          char name[53], spaceStr[23];
          int j = 0, nameInd = 0, spaceStrInd = 0;
          while (inp[j] != '.')
            name[nameInd] = inp[j], name[nameInd + 1] = '\0', nameInd++, j++;
          j++;
          while (inp[j] != '(') j++;
          j++;
          while (inp[j] != ')') {
            spaceStr[spaceStrInd] = inp[j];
            spaceStr[spaceStrInd + 1] = '\0';
            spaceStrInd++;
            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);
    }
  }
  sortNameId(trieRoot);
  for (int i = 0; i < sortedListInd; i++) {
    int nowId = sortedList[i];
    printf("%s %lld %lld\n", widget[nowId].name, widget[nowId].x,
           widget[nowId].y);
  }
  return 0;
}
