The following languages are only available languages for the problems from the contest

Kotlin Heroes: Episode 6:

- Kotlin 1.4.0

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

The problem statement has recently been changed. View the changes.

×
B. RBS Deletion

time limit per test

3 secondsmemory limit per test

512 megabytesinput

standard inputoutput

standard outputA bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence (or, shortly, an RBS) is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example:

- bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)");
- bracket sequences ")(", "(" and ")" are not.

You are given a string $$$s$$$, which is an RBS. You can apply any number of operations to this string. Each operation can have one of the following types:

- choose some non-empty prefix of $$$s$$$ and remove it from $$$s$$$, so $$$s$$$ is still an RBS. For example, we can apply this operation as follows: "(())()(())()()" $$$\to$$$ "()()" (the first $$$10$$$ characters are removed);
- choose some contiguous non-empty substring of $$$s$$$ and remove it from $$$s$$$, so $$$s$$$ is still an RBS. For example, we can apply this operation as follows: "(())()(())()()" $$$\to$$$ "(())()()()" (the characters from the $$$7$$$-th to the $$$10$$$-th are removed).

The operation $$$2$$$ can be applied at most $$$k$$$ times. Calculate the maximum number of operations you can apply until $$$s$$$ becomes empty.

Input

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^5$$$) — the number of test cases.

Each test case is described by two lines. The first line contains two integers $$$n$$$ and $$$k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$; $$$1 \le k \le n$$$; $$$n$$$ is even) — the length of $$$s$$$ and the maximum number of operations of type $$$2$$$ you can apply.

The second line contains a string $$$s$$$ of $$$n$$$ characters '(' and ')'. This string is an RBS.

The sum of $$$n$$$ over all test cases doesn't exceed $$$2 \cdot 10^5$$$.

Output

For each test case, print one integer — the maximum number of operations you can apply.

Example

Input

3 12 2 (()())((())) 6 3 ()()() 8 1 (((())))

Output

4 3 2

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: May/18/2021 00:35:39 (i2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|