CF1881A.Don't Try to Count

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Don't Try to Count

Given a string xx of length nn and a string ss of length mm (nm25n \cdot m \le 25), consisting of lowercase Latin letters, you can apply any number of operations to the string xx.

In one operation, you append the current value of xx to the end of the string xx. Note that the value of xx will change after this.

For example, if x=x ="aba", then after applying operations, xx will change as follows: "aba" \rightarrow "abaaba" \rightarrow "abaabaabaaba".

After what minimum number of operations ss will appear in xx as a substring? A substring of a string is defined as a contiguous segment of it.

Input

The first line of the input contains a single integer tt (1t1041 \le t \le 10^4) — the number of test cases.

The first line of each test case contains two numbers nn and mm (1nm251 \le n \cdot m \le 25) — the lengths of strings xx and ss, respectively.

The second line of each test case contains the string xx of length nn.

The third line of each test case contains the string ss of length mm.

Output

For each test case, output a single number — the minimum number of operations after which ss will appear in xx as a substring. If this is not possible, output 1-1.

Note

In the first test case of the example, after 22 operations, the string will become "aaaa", and after 33 operations, it will become "aaaaaaaa", so the answer is 33.

In the second test case of the example, after applying 11 operation, the string will become "eforceforc\text{e}\color{red}{\text{force}}\text{forc}", where the substring is highlighted in red.

In the fourth test case of the example, it can be shown that it is impossible to obtain the desired string as a substring.

Samples

12
1 5
a
aaaaa
5 5
eforc
force
2 5
ab
ababa
3 5
aba
ababa
4 3
babb
bbb
5 1
aaaaa
a
4 2
aabb
ba
2 8
bk
kbkbkbkb
12 2
fjdgmujlcont
tf
2 2
aa
aa
3 5
abb
babba
1 19
m
mmmmmmmmmmmmmmmmmmm
3
1
2
-1
1
0
1
3
1
0
2
5

在线编程 IDE

建议全屏模式获得最佳体验