#P1692E. Binary Deque

    ID: 1051 Type: RemoteJudge 2000ms 256MiB Tried: 0 Accepted: 0 Difficulty: 4 Uploaded By: Tags>binary searchimplementationtwo pointers*1200

Binary Deque

Description

Slavic has an array of length nn consisting only of zeroes and ones. In one operation, he removes either the first or the last element of the array.

What is the minimum number of operations Slavic has to perform such that the total sum of the array is equal to ss after performing all the operations? In case the sum ss can't be obtained after any amount of operations, you should output -1.

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

The first line of each test case contains two integers nn and ss (1n,s21051 \leq n, s \leq 2 \cdot 10^5) — the length of the array and the needed sum of elements.

The second line of each test case contains nn integers aia_i (0ai10 \leq a_i \leq 1) — the elements of the array.

It is guaranteed that the sum of nn over all test cases doesn't exceed 21052 \cdot 10^5.

For each test case, output a single integer — the minimum amount of operations required to have the total sum of the array equal to ss, or -1 if obtaining an array with sum ss isn't possible.

Input

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

The first line of each test case contains two integers nn and ss (1n,s21051 \leq n, s \leq 2 \cdot 10^5) — the length of the array and the needed sum of elements.

The second line of each test case contains nn integers aia_i (0ai10 \leq a_i \leq 1) — the elements of the array.

It is guaranteed that the sum of nn over all test cases doesn't exceed 21052 \cdot 10^5.

Output

For each test case, output a single integer — the minimum amount of operations required to have the total sum of the array equal to ss, or -1 if obtaining an array with sum ss isn't possible.

Sample Input 1

7
3 1
1 0 0
3 1
1 1 0
9 3
0 1 0 1 1 1 0 0 1
6 4
1 1 1 1 1 1
5 1
0 0 1 1 0
16 2
1 1 0 0 1 0 0 1 1 0 0 0 0 0 1 1
6 3
1 0 1 0 0 0

Sample Output 1

0
1
3
2
2
7
-1

Note

In the first test case, the sum of the whole array is 11 from the beginning, so we don't have to make any operations.

In the second test case, the sum of the array is 22 and we want it to be equal to 11, so we should remove the first element. The array turns into [1,0][1, 0], which has a sum equal to 11.

In the third test case, the sum of the array is 55 and we need it to be 33. We can obtain such a sum by removing the first two elements and the last element, doing a total of three operations. The array turns into [0,1,1,1,0,0][0, 1, 1, 1, 0, 0], which has a sum equal to 33.