CPython lite logoProblemsContests

E2. Asilbek and Configurations #2 Upsolve

Asilbek has joined the company. Asilbek's manager gave him a task. According to the task, there is a configuration file and it consists of 3 actions: 

  • { - block start.
  • } - block completion.
  • variable=value. Assign value to a variable named variable.

The value value can be of two types:

  • a number whose absolute value does not exceed 1000.
  • Another variable name. You must assign a value to this variable.

There are no extra spaces in the actions, and each action is listed on a separate line. Variable names consist of lowercase English letters and are no longer than 10 .

Initially, each variable has the value 0. The operation of assigning a value to a variable is valid until the end of the block. When the block ends, the variable returns its previous value. Asilbek's manager wants to know what level Asilbek has, so he gave him this task. Help him.


Input

The first line is the number of actions, n(1n106).

​The next n lines contain the actions.

Output

Print the new value of each variable when performing type 3 operations on a separate line.


Sample input 1

13
a=1
b=a
{
a=2
c=a
{
a=3
d=a
}
b=a
}
a=c
d=a

Sample output 1

1
1
2
2
3
3
2
0
0