Vasya writes his own library for building graphical user interface. Vasya called his creation VTK (VasyaToolKit). One of the interesting aspects of this library is that widgets are packed in each other. 

A widget is some element of graphical interface. Each widget has width and height, and occupies some rectangle on the screen. Any widget in Vasya's library is of type Widget. For simplicity we will identify the widget and its type. 

Types HBox and VBox are derivatives of type Widget, so they also are types Widget. Widgets HBox and VBox are special. They can store other widgets. Both those widgets can use the pack() method to pack directly in itself some other widget. Widgets of types HBox and VBox can store several other widgets, even several equal widgets — they will simply appear several times. As a result of using the method pack() only the link to the packed widget is saved, that is when the packed widget is changed, its image in the widget, into which it is packed, will also change. 

We shall assume that the widget *a* is packed in the widget *b* if there exists a chain of widgets *a* = *c*<sub class="lower-index">1</sub>, *c*<sub class="lower-index">2</sub>, ..., *c*<sub class="lower-index">*k*</sub> = *b*, *k* ≥ 2, for which *c*<sub class="lower-index">*i*</sub> is packed directly to *c*<sub class="lower-index">*i* + 1</sub> for any 1 ≤ *i* &lt; *k*. In Vasya's library the situation when the widget *a* is packed in the widget *a* (that is, in itself) is not allowed. If you try to pack the widgets into each other in this manner immediately results in an error.

Also, the widgets HBox and VBox have parameters border and spacing, which are determined by the methods set_border() and set_spacing() respectively. By default both of these options equal 0. 

The picture above shows how the widgets are packed into HBox and VBox. At that HBox and VBox automatically change their size depending on the size of packed widgets. As for HBox and VBox, they only differ in that in HBox the widgets are packed horizontally and in VBox — vertically. The parameter spacing sets the distance between adjacent widgets, and border — a frame around all packed widgets of the desired width. Packed widgets are placed exactly in the order in which the pack() method was called for them. If within HBox or VBox there are no packed widgets, their sizes are equal to 0 × 0, regardless of the options border and spacing. 

The construction of all the widgets is performed using a scripting language VasyaScript. The description of the language can be found in the input data. 

For the final verification of the code Vasya asks you to write a program that calculates the sizes of all the widgets on the source code in the language of VasyaScript.
The first line contains an integer *n* — the number of instructions (1 ≤ *n* ≤ 100). Next *n* lines contain instructions in the language VasyaScript — one instruction per line. There is a list of possible instructions below. 
-  "Widget [name]([x],[y])" — create a new widget [name] of the type Widget possessing the width of [x] units and the height of [y] units. -  "HBox [name]" — create a new widget [name] of the type HBox. -  "VBox [name]" — create a new widget [name] of the type VBox. -  "[name1].pack([name2])" — pack the widget [name2] in the widget [name1]. At that, the widget [name1] must be of type HBox or VBox. -  "[name].set_border([x])" — set for a widget [name] the border parameter to [x] units. The widget [name] must be of type HBox or VBox. -  "[name].set_spacing([x])" — set for a widget [name] the spacing parameter to [x] units. The widget [name] must be of type HBox or VBox. 
All instructions are written without spaces at the beginning and at the end of the string. The words inside the instruction are separated by exactly one space. There are no spaces directly before the numbers and directly after them. 

The case matters, for example, "wiDget x" is not a correct instruction. The case of the letters is correct in the input data.

All names of the widgets consist of lowercase Latin letters and has the length from 1 to 10 characters inclusive. The names of all widgets are pairwise different. All numbers in the script are integers from 0 to 100 inclusive

It is guaranteed that the above-given script is correct, that is that all the operations with the widgets take place after the widgets are created and no widget is packed in itself. It is guaranteed that the script creates at least one widget.
In the first sample the widgets are arranged as follows:
12
Widget me(50,40)
VBox grandpa
HBox father
grandpa.pack(father)
father.pack(me)
grandpa.set_border(10)
grandpa.set_spacing(20)
Widget brother(30,60)
father.pack(brother)
Widget friend(20,60)
Widget uncle(100,20)
grandpa.pack(uncle)
brother 30 60
father 80 60
friend 20 60
grandpa 120 120
me 50 40
uncle 100 20
15
Widget pack(10,10)
HBox dummy
HBox x
VBox y
y.pack(dummy)
y.set_border(5)
y.set_spacing(55)
dummy.set_border(10)
dummy.set_spacing(20)
x.set_border(10)
x.set_spacing(10)
x.pack(pack)
x.pack(dummy)
x.pack(pack)
x.set_border(0)
dummy 0 0
pack 10 10
x 40 10
y 10 10
5
Widget one(10,20)
Widget two(20,30)
Widget three(30,40)
Widget four(40,50)
Widget five(50,60)
five 50 60
four 40 50
one 10 20
three 30 40
two 20 30
16
Widget w(100,100)
VBox v
HBox h
h.set_spacing(10)
v.set_spacing(10)
v.set_border(10)
h.pack(w)
h.pack(w)
h.pack(w)
h.pack(w)
h.pack(w)
v.pack(h)
v.pack(h)
v.pack(h)
v.pack(h)
v.pack(h)
h 540 100
v 560 560
w 100 100
6
HBox hb
VBox vb
hb.pack(vb)
Widget wi(47,13)
hb.pack(wi)
vb.pack(wi)
hb 94 13
vb 47 13
wi 47 13
1
Widget a(0,0)
a 0 0
1
HBox h
h 0 0
1
VBox abcdefghij
abcdefghij 0 0
20
VBox hykl
VBox enwv
enwv.pack(hykl)
VBox dlepf
dlepf.pack(hykl)
enwv.set_border(30)
Widget mjrrik(54,21)
hykl.set_border(2)
dlepf.set_border(22)
enwv.set_border(3)
enwv.pack(dlepf)
dlepf.pack(mjrrik)
hykl.set_spacing(96)
enwv.set_border(32)
dlepf.set_border(72)
Widget j(54,86)
hykl.pack(j)
enwv.set_border(54)
hykl.set_border(88)
hykl.set_border(86)
dlepf 370 423
enwv 478 789
hykl 226 258
j 54 86
mjrrik 54 21
18
HBox pack
VBox vbox
Widget widget(10,10)
pack.pack(widget)
HBox hbox
hbox.pack(widget)
HBox set
HBox se
HBox s
VBox border
VBox spacing
set.set_border(3)
set.set_spacing(3)
se.set_spacing(5)
s.set_border(6)
border.set_border(7)
spacing.set_spacing(9)
vbox.pack(pack)
border 0 0
hbox 10 10
pack 10 10
s 0 0
se 0 0
set 0 0
spacing 0 0
vbox 10 10
widget 10 10
3
HBox ox
Widget idget(5,5)
ox.pack(idget)
idget 5 5
ox 5 5
4
VBox ox
Widget idge(50,60)
ox.pack(idge)
ox.set_border(5)
idge 50 60
ox 60 70
5
HBox package
VBox packing
package.pack(packing)
Widget packpackpa(13,13)
packing.pack(packpackpa)
package 13 13
packing 13 13
packpackpa 13 13
import re

class Widget(object):
  def calc_wh(self):
    if not hasattr(self, "w"):
      if self.children:
        self.w = 0
        self.h = 0
        for c in self.children:
          cw, ch = c.calc_wh()
          if self.type == "VBox":
            self.h += ch
            self.w = max(self.w, cw)
          else:
            self.w += cw
            self.h = max(self.h, ch)

        if self.type == "HBox":
          self.w += (len(self.children)-1)*self.spacing
        else:
          self.h += (len(self.children)-1)*self.spacing
        self.h += 2*self.border
        self.w += 2*self.border
      else:
        self.w = 0
        self.h = 0

    return self.w, self.h

widgets = {}

n = input()
regexp = re.compile(r"(\w+)\.(\w+)\((.+)\)")

for _ in xrange(n):
  str = raw_input()
  if str.find(' ') != -1:
    type, rhs = str.split(' ')
    if type == 'Widget':
      name, other = rhs.split('(')
      w, h = map(int, other[:-1].split(','))
      widgets[name] = Widget()
      widgets[name].w = w
      widgets[name].h = h
      widgets[name].type = type
    else:
      widgets[rhs] = Widget()
      widgets[rhs].type = type
      widgets[rhs].children = []
      widgets[rhs].spacing = 0
      widgets[rhs].border = 0
  else:
    m = regexp.match(str)
    name = m.group(1)
    op = m.group(2)
    arg = m.group(3)

    if op == "set_border":
      widgets[name].border = int(arg)
    elif op == "set_spacing":
      widgets[name].spacing = int(arg)
    else:
      widgets[name].children.append(widgets[arg])


for k, v in sorted(widgets.items()):
  w, h = v.calc_wh()
  print k, w, h