Generating Strings
题号:NC220441
时间限制:C/C++/Rust/Pascal 1秒,其他语言2秒
空间限制:C/C++/Rust/Pascal 1024 M,其他语言2048 M
64bit IO Format: %lld

题目描述

Mr. Chaos is a high school student. Teachers always ask him to write a lot of compositions, but he isn't interested in it at all. Tired of generating meaningless words by himself, he invented a machine to help him.

His teacher has posted the model article -- string , on the blackboard. His machine can generate any lowercase string of length at a time. For a fixed string , the scoring method is simple: for any pair of integers such that the substring is a palindrome, the final score will be added by the number that occurs in . Formally, let's define as the string , a string is palindromic if it remains the same string when reversing, and the occurrence time  of in , , is the number of pairs of such that . Then, the value of , namely , is defined as

For example, given , when the machine generated a string , one of its palindromic substrings will be . is because  occurs in twice. Note that there are two in this case, and they are considered as different substrings and calculated twice.

As Mr. Chao's best friend, you are asked to tell him the sum of value of all the that his machine can generate.

You accept this mission without thinking twice. However, it seems that you are getting into trouble, because the teacher makes revisions on string . Each time the last character will be deleted or a new character will be added to the end. So now you have to answer the question for times.

Formally, let be the set of all strings of length that only contain lowercase English letters. You are going to calculate this formula

at the beginning and after each revision of , that is, in total times. As the answer may be too large, you only need to output its remainder modulo

输入描述:

The first line contains one integer  --- the number of test cases. Then  test cases follow.

The first line of each test case contains two integers and one string :  --- the length of the string that machine can generate, the number of revision and the original article . It is guaranteed that  only contain lowercase English letters.

Each of the next  lines indicates a revision, in the order that they are made. The format will either be  , which means that the character  is added to the end of , or , which means that the last character of  is deleted. It is guaranteed that  is a lowercase English letter.

It is guaranteed that in a single test file, the sum of , the sum of , and the sum of the length of  among all test cases do not exceed .


输出描述:

For each test case print m+1 lines, each containing a single integer. The first line should be the answer of the original S, while the next m lines should be the answer after each revision. Note that you only need to print them modulo .
示例1

输入

复制
3
6 3 aaa
2
1 b
1 a
5 3 aabaaa
2
2
2
6 2 aababa
1 a
1 b

输出

复制
218504832
144861392
216149648
287508208
13924249
11567037
9211852
6924944
430225380
503798516
575088800