class Solution:
def search(self, nums: List[int], target: int) -> int:
l,r=0,len(nums)-1#区间起始,区间结束位置
while (l<=r):
mid=(l+r)//2
if nums[mid]==target:
return mid
elif nums[mid]>target:
r=mid-1
else:
l=mid+1
return -1
2找出数组排序后的目标下标
class Solution:
def targetIndices(self, nums: List[int], target: int) -> List[int]:
nums.sort()
la=[]
while True:
if target in nums:
i=nums.index(target)
la.append(i)
nums[i]='s'
else:
break
return la
4 binary deque
t=int(input())
lb=[]
def solve(n,s,nums):
la=[0]*(n+1)
for i in range(1,n+1):
la[i]=la[i-1]+nums[i]
s1=ans=float("inf")
r=1
for i in range(1,n+1):
while r<n and la[r+1]-la[i-1]<=s:
r=r+1
if la[r]-la[i-1]==s:
ans=min(ans,n-(r-i+1))
if ans==s1:
lb.append(-1)
else:
lb.append(ans)
for i in range(t):
n, s = map(int, input().split())
nums = [0] + list(map(int, input().split()))
solve(n,s,nums)
for i in lb:
print(i)