NIO is playing a string game with OIN. If you don't know this game, here're the rules:
OIN writes down a main string

and a set

with

strings

, and NIO needs to answer the number of strings in

that are lexicographically less than

as fast as possible.
However, it is too easy for NIO to solve this problem, so OIN decides to make the problem a little more difficult. Now he has four kinds of operations:
-
, add one lowercase Latin letter
at the back of string
(
).
-
, erase the last
letters of string
, where
.
-
, add
lowercase Latin letters
at the back of string
(
).
-
, ask the number of strings in
that is strictly lexicographically less than
.
OIN will do the operations above for

times. However, it is still easy for NIO, and he thinks it is boring, so he wants you to write a program to solve it automatically.
String

is lexicographically less than string

if

and one of two following conditions is satisfied:
-
is a prefix of the string
;
- For some
, the first
characters of the string
are equal to the corresponding characters of the string
, and
.