欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1881A.Don't Try to Count
Don't Try to Count
Given a string of length and a string of length (), consisting of lowercase Latin letters, you can apply any number of operations to the string .
In one operation, you append the current value of to the end of the string . Note that the value of will change after this.
For example, if "aba", then after applying operations, will change as follows: "aba" "abaaba" "abaabaabaaba".
After what minimum number of operations will appear in 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 () — the number of test cases.
The first line of each test case contains two numbers and () — the lengths of strings and , respectively.
The second line of each test case contains the string of length .
The third line of each test case contains the string of length .
Output
For each test case, output a single number — the minimum number of operations after which will appear in as a substring. If this is not possible, output .
Note
In the first test case of the example, after operations, the string will become "aaaa", and after operations, it will become "aaaaaaaa", so the answer is .
In the second test case of the example, after applying operation, the string will become "", 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
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |