欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1670B.Dorms War
Dorms War
Hosssam decided to sneak into Hemose's room while he is sleeping and change his laptop's password. He already knows the password, which is a string of length . He also knows that there are special letters of the alphabet: .
Hosssam made a program that can do the following.
- The program considers the current password of some length .
- Then it finds all positions () such that is one of the special letters.
- Then it deletes all of those positions from the password even if is a special character. If there are no positions to delete, then the program displays an error message which has a very loud sound.
For example, suppose the string is "abcdef" and the special characters are 'b' and 'd'. If he runs the program once, the positions and will be deleted as they come before special characters, so the password becomes "bdef". If he runs the program again, it deletes position , and the password becomes "def". If he is wise, he won't run it a third time.
Hosssam wants to know how many times he can run the program on Hemose's laptop without waking him up from the sound of the error message. Can you help him?
Input
The first line contains a single integer () — the number of test cases. Then test cases follow.
The first line of each test case contains a single integer () — the initial length of the password.
The next line contains a string consisting of lowercase English letters — the initial password.
The next line contains an integer (), followed by distinct lowercase letters — the special letters.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, print the maximum number of times Hosssam can run the program without displaying the error message, on a new line.
Note
In the first test case, the program can run times as follows: $\text{iloveslim} \to \text{ilovslim} \to \text{iloslim} \to \text{ilslim} \to \text{islim} \to \text{slim}$
In the second test case, the program can run times as follows:
In the third test case, the program can run times as follows: $\text{basiozi} \to \text{bioi} \to \text{ii} \to \text{i}$.
In the fourth test case, the program can run times as follows: $\text{khater} \to \text{khatr} \to \text{khar} \to \text{khr} \to \text{kr} \to \text{r}$
In the fifth test case, the program can run only once as follows:
In the sixth test case, the program cannot run as none of the characters in the password is a special character.
Samples
10
9
iloveslim
1 s
7
joobeel
2 o e
7
basiozi
2 s i
6
khater
1 r
7
abobeih
6 a b e h i o
5
zondl
5 a b c e f
6
shoman
2 a h
7
shetwey
2 h y
5
samez
1 m
6
mouraz
1 m
5
2
3
5
1
0
3
5
2
0
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |