Problem: There are people taking part in a show about VOCALOID. They will sit in the row of seats, numbered to from left to right.
The people come and sit in order. Each person occupies a seat in one of three ways:
- Sit in the seat next to the left of the leftmost person who is already sitting, or if seat is taken, then leave the show. If there is no one currently sitting, sit in seat .
- Sit in the seat next to the right of the rightmost person who is already sitting, or if seat is taken, then leave the show. If there is no one currently sitting, sit in seat .
- Sit in the seat numbered . If this seat is taken, then leave the show.
Now you want to know what is the maximum number of people that can take a seat, if you can let people into the show in any order?
Input Format: Each test consists of multiple test cases. The first line contains a single integer () — the number of test cases. The description of test cases follows.
The first line of each test case contains two integers and () — the number of people and the number of seats.
The second line of each test case contains integers (, ), the -th of which describes the way in which the -th person occupies a seat:
- If , then -th person takes the seat in the first way.
- If , then -th person takes the seat in the second way.
- If , then the -th person takes a seat in the third way, i.e. he wants to sit in the seat with the number or leave the show if it is occupied..
It is guaranteed that sum of and the sum of over all test cases don't exceed .
Output Format: For each test case output a single integer — the maximum number of people who can occupy a seat.
Note: In the first test case, all the people want to occupy the seat, so only people can occupy the seat.
In the second test case, we can let people in order , then all but the last person can take a seat.
In the third test case, we can let people into the show in that order:
Let the third person in:
–––3–––
Let the fourth person in:
–––34––
Let the fifth person in:
–––345–
Let the first person in:
––1345–
Let the second person in:
–21345–
Thus, all people took seats.
In the fifth test case, we can let people into the show in this order:
Let the fourth person in:
––––4–
Let the third person in:
–––34–
Let the sixth person in, he'll leave the show because he takes the third seat the third way and has to sit in the seat, but it's already taken:
–––34–
Let the fifth person in:
––534–
Let the first person in:
–1534–
Let the second person in:
21534–
Thus, of people took seats.
In the seventh test case, we can let people into the show in this order:
Let the third person in:
3––––––
Let the fourth person in:
34–––––
Let the fifth person in:
345––––
Let the sixth person in:
3456–––
Let the first person in:
34561––
Let the second person in, he will leave the show because he occupies the first way, but the seat is taken:
34561––
Thus, people took seats.