#P3689. [ZJOI2017] 多项式

[ZJOI2017] 多项式

Description

Kotori Itsuka recently studied the properties of polynomials with coefficients modulo 2. She found that one can obtain a very long string using multiplication of polynomials modulo 2:

For an nn-degree polynomial f(x)f\left( x \right) with coefficients 0 or 1, we compute g(x)=f(x)mg\left( x \right) = f\left( x \right)^{m} modulo 2. Then g(x)g\left( x \right) is an nmnm-degree polynomial with nm+1nm + 1 coefficients. Writing these coefficients from the highest degree to the lowest degree gives a 01 string of length nm+1nm + 1.

For example, for the polynomial f(x)=x3+x+1f\left( x \right) = x^{3} + x + 1, we compute $g\left( x \right) = f\left( x \right)^{3} = x^{9} + x^{7} + x^{6} + x^{5} + x^{2} + x^{1} + 1$, thus we obtain a string of length 10: 1011100111.

Now given a polynomial f(x)f\left( x \right) of degree nn, integers mm, LL, RR, and a 01 string tt of length KK. Let ss be the string obtained from f(x)mf\left( x \right)^{m}, and let s[L,R]s\left[ L, R \right] denote the substring from the LL-th character to the RR-th character of ss. Kotori wants to know how many times tt appears in s[L,R]s\left[ L, R \right].

Input Format

The first line contains an integer TT denoting the number of test cases.

For each test case, the first line contains five integers n,m,K,L,Rn, m, K, L, R.

The second line contains a 01 string of length n+1n + 1 representing the coefficients of the polynomial f(x)f\left( x \right). The ii-th character represents the coefficient of degree ni+1n - i + 1 of f(x)f\left( x \right).

The third line contains a string of length KK representing the string tt.

Output Format

For each test case, output a single integer denoting the answer.

1
3 3 2 1 10
1011
01
2

Hint

Time and Space Limit

Time limit: 3 s, Memory limit: 512 MB.

Constraints

Translated by ChatGPT 5