## GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

## Dorms War Codeforces Solution | Codeforces Problem Solution 2022

B. Dorms War
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 $s$ of length $n$. He also knows that there are $k$ special letters of the alphabet: ${c}_{1},{c}_{2},\dots ,{c}_{k}$.

Hosssam made a program that can do the following.

1. The program considers the current password $s$ of some length $m$.
2. Then it finds all positions $i$ ($1\le i) such that ${s}_{i+1}$ is one of the $k$ special letters.
3. Then it deletes all of those positions from the password $s$ even if ${s}_{i}$ 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 $s$ is "abcdef" and the special characters are 'b' and 'd'. If he runs the program once, the positions $1$ and $3$ will be deleted as they come before special characters, so the password becomes "bdef". If he runs the program again, it deletes position $1$, 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 $t$ ($1\le t\le {10}^{5}$) — the number of test cases. Then $t$ test cases follow.

The first line of each test case contains a single integer $n$ ($2\le n\le {10}^{5}$) — the initial length of the password.

The next line contains a string $s$ consisting of $n$ lowercase English letters — the initial password.

The next line contains an integer $k$ ($1\le k\le 26$), followed by $k$ distinct lowercase letters ${c}_{1},{c}_{2},\dots ,{c}_{k}$ — the special letters.

It is guaranteed that the sum of $n$ over all test cases does not exceed $2\cdot {10}^{5}$.

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.