Codeforces Round 725 (Div. 3) |
---|
Finished |
Polycarp came up with a new programming language. There are only two types of statements in it:
All variable names and strings only consist of lowercase letters of the English alphabet and do not exceed $$$5$$$ characters.
The result of the program is the number of occurrences of string haha in the string that was written to the variable in the last statement.
Polycarp was very tired while inventing that language. He asks you to implement it. Your task is — for given program statements calculate the number of occurrences of string haha in the last assigned variable.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^3$$$). Then $$$t$$$ test cases follow.
The first line of each test case contains a single integer $$$n$$$ ($$$1 \le n \le 50$$$) — the number of statements in the program. All variable names and strings are guaranteed to consist only of lowercase letters of the English alphabet and do not exceed $$$5$$$ characters.
This is followed by $$$n$$$ lines describing the statements in the format described above. It is guaranteed that the program is correct.
For each set of input data, output the number of occurrences of the haha substring in the string that was written to the variable in the last statement.
4 6 a := h b := aha c = a + b c = c + c e = c + c d = a + c 15 x := haha x = x + x x = x + x x = x + x x = x + x x = x + x x = x + x x = x + x x = x + x x = x + x x = x + x x = x + x x = x + x x = x + x x = x + x 1 haha := hah 5 haahh := aaaha ahhhh = haahh + haahh haahh = haahh + haahh ahhhh = ahhhh + haahh ahhaa = haahh + ahhhh
3 32767 0 0
In the first test case the resulting value of d is hhahahaha.
Name |
---|