Ternary String Revolution

아직 제출이 없습니다시간 제한1초메모리 제한256 MB

문제

A ternary string is a sequence of digits, where each digit is either 00, 11, or 22.

For a ternary string, Chiaki can perform any of the following operations:

  • Replace one occurrence of 0000 to 1212 or vice versa. For example, 120011120011 can change to 121211121211 or 000011000011.
  • Replace one occurrence of 111111 to 2020 or vice versa. For example, 11120111112011 can change to 202011202011 or 1111111111111111.
  • Remove one occurrence of 2222 or put string 2222 on any position (you can also put it at the beginning or the ending of the string). For example, 12211221 can change to 1111,  221221221221, 122221122221 or 122122122122.
  • Remove one occurrence of 012012 or put string 012012 on any position (you can also put it at the beginning or the ending of the string). For example, 1012110121 can change to 1111,  0121012101210121, 1012012110120121, 1001212110012121, 1010122110101221, 1012012110120121 or 1012101210121012.

Chiaki has a ternary string ss of length nn and mm other ternary strings t_1,t_2,,t_mt\_1,t\_2,\dots,t\_m. For each ternary string t_it\_i, she would like to know the number of pairs (l,r)(l, r) (1lrn1 \le l \le r \le n) such that the substring s_l..rs\_{l..r} can become t_it\_i after performing several above operations.

입력

There are multiple test cases. The first line of input contains an integer TT, indicating the number of test cases. For each test case:

The first line contains two integers nn and mm (1n,m1061 \le n, m \le 10^6) -- the length of ss and the number of other ternary strings.

The second line contains a ternary string ss of length nn.

Each of the next mm lines contains a ternary string t_it\_i (1t_i1061 \le |t\_i| \le 10^6).

It is guaranteed that the sum of the length of all strings over all test cases does not exceed 2×1062 \times 10^6.

출력

For each test cases, output mm lines, where the ii-th line contains an integer denoting the answer for ternary string t_it\_i.