8541: AC/DC

内存限制:128 MB 时间限制:8 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:0

题目描述

J likes playing electric guitar, especially the famous guitar model - Gibson SG Standard. He always composes music with his Gibson SG Standard.

A tune he composes is made up of several notes. Formally, tune can be regarded as a string consisting of only lower-case letters. Different letters stands for different notes. A substring of a tune is called phrase.

At the beginning, J has a tune of length n. To create new music, J has three operations:

  • 1 c : Insert a note cc at the end of the current tune.
  • 2 : Delete the note at the beginning of the current tune.
  • 3 t : Query the number of the phrase t appears in the current tune.

Now, J is busy with his new album and invites you to write music together. Can you help him with it?

输入格式

The first line contains a single integer T (1T5), the number of test cases. For each test case:

The first line contains a string SS of length n(1n105) indicating the initial tune.

The next line contains one integer m(1m105) indicating the number of operations.

For the following mm lines, the i-th line contains an operation like 1 c2 or '3 t.

Let's define the last answer as lastanslastans. At the beginning, lastans = 0lastans=0.

  • For 1 c, the real operation is c=((ca)lastans)mod26+a.
  • For 3 t, the real operation is for every 1it, ti=((tia)lastans)mod26+a.

It's guaranteed that c is a lower-case letter. t is a string consisting only of lower-case letters. The sum of the lengths of t of all test cases will not exceed 5×106.

Note that string SS may be deleted to an empty string. But it's guaranteed that there will be no operations of type 2 at this time.

输出格式

For each query \mathtt{3\ t}3 t, print a single integer in a single line indicating the answer.

输入样例 复制

1
abcbaba
5
3 ab
3 c
1 a
2
3 da

输出样例 复制

2
3
1