CF1968B.Prefiquence

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

Prefiquence

You are given two binary strings aa and bb. A binary string is a string consisting of the characters '0' and '1'.

Your task is to determine the maximum possible number kk such that a prefix of string aa of length kk is a subsequence of string bb.

A sequence aa is a subsequence of a sequence bb if aa can be obtained from bb by the deletion of several (possibly, zero or all) elements.

Input

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

The first line of each test case contains two integers nn and mm (1n,m21051\le n,m \le 2 \cdot 10^5) — the length of string aa and the length of string bb, respectively.

The second line of each test case contains a binary string aa of length nn.

The third line of each test case contains a binary string bb of length mm.

It is guaranteed that the sum of values nn over all test cases does not exceed 21052 \cdot 10^5. Similarly, the sum of values mm over all test cases does not exceed 21052 \cdot 10^5.

Output

For each test case, output a single number — the maximum kk, such that the first kk characters of aa form a subsequence of bb.

Note

In the first example, the string '1010' is a subsequence of '11101\color{red}11\color{red}0' but the string '100100' is not. So the answer is 22.

In the fifth example, aa='100100', bb='110101\color{red}{10}1\color{red}0', whole string aa is a subsequence of string bb. So the answer is 33.

In the sixth example, string bb does not contain '11' so the answer is 00.

Samples

6
5 4
10011
1110
3 3
100
110
1 3
1
111
4 4
1011
1111
3 5
100
11010
3 1
100
0
2
2
1
1
3
0

在线编程 IDE

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