QOJ.ac

QOJ

Limite de temps : 3 s Limite de mémoire : 512 MB Points totaux : 100

#5215. Polynomial

Statistiques

Kearan has recently been studying the properties of polynomials with coefficients modulo 2. She discovered that one can obtain a very long string using polynomial multiplication modulo 2:

For a polynomial $f(x)$ of degree $n$ with coefficients 0 or 1, we calculate $g(x) = f(x)^m$ modulo 2. Then $g(x)$ is a polynomial of degree $nm$, which has $nm + 1$ coefficients. By writing these coefficients down from the highest degree to the lowest, we can obtain a 01-string of length $nm + 1$.

For example, for the polynomial $f(x) = x^3 + x + 1$, calculating $g(x) = f(x)^3 = x^9 + x^7 + x^6 + x^5 + x^2 + x + 1$ gives us a string of length 10: 1011100111.

Now, Kearan has a polynomial $f(x)$ of degree $n$, integers $m, L, R$, and a 01-string $t$ of length $K$. Let $s$ be the string obtained from $f(x)^m$, and $s[L, R]$ be the substring of $s$ from the $L$-th character to the $R$-th character. Kearan wants to know how many times $t$ appears in $s[L, R]$.

Input

The first line contains an integer $T$, representing the number of test cases.

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

The second line contains a 01-string of length $n + 1$ representing the coefficients of the polynomial $f(x)$, where the $i$-th character represents the coefficient of the $x^{n-i+1}$ term of $f(x)$.

The third line contains a string of length $K$ representing the string $t$.

Output

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

Constraints

Test Case ID $n$ $m$ $K$ Other Constraints
1 $\le 18$ $\le 500$ $\le 18$ None
2 $\le 18$ $\le 2 \times 10^5$ $\le 18$ None
3 $\le 18$ $\le 2 \times 10^5$ $\le 18$ None
4 $\le 18$ $\le 10^{16}$ $\le 18$ $R - L \le 10^4$
5 $\le 18$ $\le 10^{16}$ $\le 18$ $R - L \le 10^4$
6 $\le 18$ $\le 10^{16}$ $\le 18$ $R - L \le 10^4$
7 $\le 18$ $\le 10^{16}$ $\le 18$ $L = 1, R = nm + 1$
8 $\le 18$ $\le 10^{16}$ $\le 18$ $L = 1, R = nm + 1$
9 $\le 18$ $\le 10^{16}$ $\le 18$ None
10 $\le 18$ $\le 10^{16}$ $\le 18$ None

For 100% of the data, it is guaranteed that $1 \le T \le 5$ and $1 \le L \le R \le nm + 1$.

Examples

Input 1

1
3 3 2 1 10
1011
01

Output 1

2

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.