NIO with String Game
题号:NC239343
时间限制:C/C++/Rust/Pascal 2秒,其他语言4秒
空间限制:C/C++/Rust/Pascal 512 M,其他语言1024 M
64bit IO Format: %lld

题目描述

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 s and a set G with n strings , and NIO needs to answer the number of strings in G that are lexicographically less than s 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:

  • 1 i c , add one lowercase Latin letter c at the back of string t_i().
  • 2 p , erase the last p letters of string s, where .
  • 3 k c, add k lowercase Latin letters c at the back of string s().
  • 4 , ask the number of strings in G that is strictly lexicographically less than s.

OIN will do the operations above for q 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 a is lexicographically less than string b if  and one of two following conditions is satisfied:
  •  a is a prefix of the string b;
  • For some i, the first i characters of the string a are equal to the corresponding characters of the string b, and .

输入描述:

The first line contains two integers n and q --- the number of strings in G and the number of operations ().

The second line contains a string s consisting of no more than  lowercase Latin letters.

The i-th of the next n line contains one string t_i, which is in the set G. It is guaranteed that the total length of strings in G does not exceed .

The following q lines contain descriptions of operations.

All strings contain only lowercase Latin letters, s will never be an empty string

输出描述:

For each operator 4, output one line containing a single integer---the answer to the question.
示例1

输入

复制
6 11
abe
aaa
aa
aab
aac
abd
bc
4
2 1
4
3 1 d
4
3 2 a
4
2 4
4
1 3 d
4

输出

复制
5
4
4
5
0
0