#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct candy
{
    int h, m;
    bool operator < (candy c) const
    {
        return h < c.h;
    }
    candy(int _h, int _m) : h(_h), m(_m) {}
};

vector<candy> candies_start[2];

int main()
{
    candies_start[0].reserve(2000);
    candies_start[1].reserve(2000);

    int n, x;

    cin >> n >> x;

    for (int i = 0, t, h, m; i < n; i++)
    {
        cin >> t >> h >> m;
        candies_start[t].push_back(candy(h, m));
    }

    sort(candies_start[0].begin(), candies_start[0].end());
    sort(candies_start[1].begin(), candies_start[1].end());

    int answer = 0;

    for (int t = 0; t < 2; t++)
    {
        bool next_type = t;
        int max_jump = x;

        vector<candy> candies_current[2];
        candies_current[0] = candies_start[0];
        candies_current[1] = candies_start[1];

        int count = 0;

        while (true)
        {
            vector<candy>::iterator best_i;
            int best_v = -1;

            for (auto it = candies_current[next_type].begin(); it != candies_current[next_type].end(); it++)
            {
                if (it->h > max_jump)
                {
                    break;
                }

                if (it->m > best_v)
                {
                    best_i = it;
                    best_v = it->m;
                }
            }

            if (best_v == -1)
            {
                break;
            }

            max_jump += best_v;
            candies_current[next_type].erase(best_i);
            next_type = !next_type;

            count++;

        }

        answer = max(answer, count);
    }

    cout << answer << endl;

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct candy
{
    bool t;
    int h, m;
    bool operator < (candy c) const
    {
        return h < c.h;
    }
};

vector<candy> candies_start;

int main()
{
    int n, x;

    cin >> n >> x;

    candies_start.resize(n);

    for (int i = 0; i < n; i++)
    {
        cin >> candies_start[i].t >> candies_start[i].h >> candies_start[i].m;
    }

    sort(candies_start.begin(), candies_start.end());

    int answer = 0;

    for (int t = 0; t < 2; t++)
    {
        bool next_type = t;
        int max_jump = x;
        vector<candy> candies_current = candies_start;

        while (!candies_current.empty())
        {
            for (auto it = candies_current.begin(); it != candies_current.end(); it++)
            {
                if (it->h > max_jump)
                {
                    goto end;
                }

                if (it->t == next_type)
                {
                    max_jump += it->m;
                    next_type = !next_type;
                    candies_current.erase(it);
                    break;
                }
            }
        }

        end:
        answer = max(answer, (int)(candies_start.size() - candies_current.size()));
    }

    cout << answer << endl;

    return 0;
}


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

M = mod = 998244353
def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))))
def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip('\n').split(' ')]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n').split(' ')]
def li3():return [int(i) for i in input().rstrip('\n')]

# print(inv_mod(2))
# for i in range(1,100):
#     if (inv_mod(i)*3)%mod == 124780545:print(i)

# for _ in range(val()):
#     n, m = li()
#     a = li()
#     b = li()
#     s = set()
#     ans = j = 0
#     for i in b:
#         if i not in s:
#             while a[j]!= i:
#                 s.add(a[j])
#                 j += 1
#             ans += 2*len(s)
#             ans += 1
#             j += 1
#         else:
#             s.remove(i)
#             ans += 1
#     print(ans)

for _ in range(val()):
    n, s = li()
    l = li()
    heap = []
    i = 0
    d = {}
    while i<n:
        if s - l[i] >= 0:
            d[-l[i]] = i
            heapq.heappush(heap,-l[i])
            s -= l[i]
        else:
            break
        i += 1
    if i == n or i == 0:
        print(0)
    else:
        sumprev = len(heap)
        ans = heapq.heappop(heap)
        # print(ans)
        s += -ans
        while i<n:
            if s - l[i] >= 0:
                heapq.heappush(heap,-l[i])
                s -= l[i]
            else:
                break
            i += 1

        if len(heap) <= sumprev:
            print(0)
        else:
            print(d[ans] + 1)


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

# M = mod = 10**9 + 7
def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))))
# def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip('\n').split(' ')]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n').split(' ')]
def li3():return [int(i) for i in input().rstrip('\n')]

for _ in range(val()):
    n, s = li()
    l = li()
    heap = []
    i = 0
    d = {}
    while i<n:
        if s - l[i] >= 0:
            d[-l[i]] = i
            heapq.heappush(heap,-l[i])
            s -= l[i]
        else:
            break
        i += 1
    if i == n:
        print(0)
    else:
        if len(heap) == 0:
            i += 1
            d[l[0]] = 0
            ans = l[0]
            temp = 0
        else:
            ans = heapq.heappop(heap)
            s += -ans
            temp = i
        while i<n:
            if s - l[i] >= 0:
                heapq.heappush(heap,-l[i])
                s -= l[i]
            else:
                break
            i += 1
        # print(i,temp)
        if i == temp:
            print(0)
        else:
            print(d[ans] + 1)


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

M = mod = 998244353
def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))))
def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip('\n').split(' ')]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n').split(' ')]
def li3():return [int(i) for i in input().rstrip('\n')]

# print(inv_mod(2))
# for i in range(1,100):
#     if (inv_mod(i)*3)%mod == 124780545:print(i)

# for _ in range(val()):
#     n, m = li()
#     a = li()
#     b = li()
#     s = set()
#     ans = j = 0
#     for i in b:
#         if i not in s:
#             while a[j]!= i:
#                 s.add(a[j])
#                 j += 1
#             ans += 2*len(s)
#             ans += 1
#             j += 1
#         else:
#             s.remove(i)
#             ans += 1
#     print(ans)

for _ in range(val()):
    n, s = li()
    l = li()
    su = sum(l)
    ans = 0
    l2 = sorted(l)
    d = defaultdict(int)
    for i in l:d[i] += 1
    while su - l2[-1]>s and len(l):
        su -= l[-1]
        d[l.pop()] -= 1
        while len(l2) and not d[l2[-1]]:l2.pop()
        ans = l.index(l2[-1]) + 1
    print(ans  )


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

# M = mod = 10**9 + 7
def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))))
# def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip('\n').split(' ')]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n').split(' ')]
def li3():return [int(i) for i in input().rstrip('\n')]

for _ in range(val()):
    n, s = li()
    l = li()
    heap = []
    i = 0
    d = {}
    while i<n:
        if s - l[i] >= 0:
            d[-l[i]] = i
            heapq.heappush(heap,-l[i])
            s -= l[i]
        else:
            break
        i += 1
    if i == n:
        print(0)
    else:
        if len(heap) == 0:
            print(0)
            exit()
        ans = heapq.heappop(heap)
        s += -ans
        temp = i
        while i<n:
            if s - l[i] >= 0:
                heapq.heappush(heap,-l[i])
                s -= l[i]
            else:
                break
            i += 1
        # print(i,temp)
        if i == temp:
            print(0)
        else:
            print(d[ans] + 1)


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

# M = mod = 10**9 + 7
def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))))
# def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip('\n').split(' ')]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n').split(' ')]
def li3():return [int(i) for i in input().rstrip('\n')]

for _ in range(val()):
    n, s = li()
    l = li()
    heap = []
    i = 0
    d = {}
    while i<n:
        if s - l[i] >= 0:
            d[-l[i]] = i
            heapq.heappush(heap,-l[i])
            s -= l[i]
        else:
            break
        i += 1
    if i == n:
        print(0)
    else:
        if len(heap) == 0:
            i += 1
            d[l[0]] = 0
            ans = l[0]
        else:
            ans = heapq.heappop(heap)
            s += -ans
        temp = i
        while i<n:
            if s - l[i] >= 0:
                heapq.heappush(heap,-l[i])
                s -= l[i]
            else:
                break
            i += 1
        # print(i,temp)
        if i == temp:
            print(0)
        else:
            print(d[ans] + 1)


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

# M = mod = 10**9 + 7
def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))))
# def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip('\n').split(' ')]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n').split(' ')]
def li3():return [int(i) for i in input().rstrip('\n')]

for _ in range(val()):
    n, s = li()
    l = li()
    heap = []
    i = 0
    d = {}
    while i<n:
        if s - l[i] >= 0:
            d[-l[i]] = i
            heapq.heappush(heap,-l[i])
            s -= l[i]
        else:
            break
        i += 1
    if i == n:
        print(0)
    else:
        ans = heapq.heappop(heap)
        s += -ans
        temp = i
        while i<n:
            if s - l[i] >= 0:
                heapq.heappush(heap,-l[i])
                s -= l[i]
            else:
                break
            i += 1
        # print(i,temp)
        if i == temp:
            print(0)
        else:
            print(d[ans] + 1)


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

# M = mod = 10**9 + 7
def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))))
# def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip('\n').split(' ')]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n').split(' ')]
def li3():return [int(i) for i in input().rstrip('\n')]

for _ in range(val()):
    n, s = li()
    l = li()
    heap = []
    i = 0
    d = {}
    while i<n:
        if s - l[i] >= 0:
            d[-l[i]] = i
            heapq.heappush(heap,-l[i])
            s -= l[i]
        else:
            break
        i += 1
    if i == n:
        print(0)
    else:
        if len(heap) == 0:
            i = 1
            d[-l[0]] = 0
            ans = -l[0]
            temp = 1
        else:
            ans = heapq.heappop(heap)
            s += -ans
            temp = i
        while i<n:
            if s - l[i] >= 0:
                heapq.heappush(heap,-l[i])
                s -= l[i]
            else:
                break
            i += 1
        # print(i,temp)
        if i == temp:
            print(0)
        else:
            print(d[ans] + 1)


from bisect import bisect_left as bl
from bisect import bisect_right as br
import heapq
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline

# M = mod = 10**9 + 7
def factors(n):return sorted(list(set(reduce(list.__add__,([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))))
# def inv_mod(n):return pow(n, mod - 2, mod)

def li():return [int(i) for i in input().rstrip('\n').split(' ')]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n').split(' ')]
def li3():return [int(i) for i in input().rstrip('\n')]

for _ in range(val()):
    n, s = li()
    l = li()
    l2 = sorted(l)
    heap = []
    i = 0
    while i<n:
        heapq.heappush(heap,-l[i])
        i += 1
    su = sum(-i for i in heap)
    tot = 0
    while su>s and len(heap):
        tot += 1
        su += heapq.heappop(heap)
    print(tot)


t=int(input())
for i in range(t):
    n,s=map(int,input().split())
    arr=list(map(int,input().split()))

    def solve(arr,n,s):
        if s>=sum(arr):
            return 0

        index=0
        sum_x=0
        for i in range(n):
            sum_x+=arr[i]
            if sum_x>s:
                index=i
                break
        brr=[arr[i] for i in range(index+1)]
        return brr.index(max(brr))+1
    print(solve(arr,n,s))


t=int(input())
for i in range(t):
    n,s=map(int,input().split())
    arr=list(map(int,input().split()))

    def solve(arr,n,s):
        if s>=sum(arr):
            return 0

        index=0
        sum_x=0
        for i in range(n):
            sum_x+=arr[i]
            if sum_x>=s:
                index=i
                break
        brr=[arr[i] for i in range(index+1)]
        return brr.index(max(brr))+1
    print(solve(arr,n,s))


import sys
import math
import heapq
import collections
def inputnum():
    return(int(input()))
def inputnums():
    return(map(int,input().split()))
def inputlist():
    return(list(map(int,input().split())))
def inputstring():
    return([x for x in input()])
def inputstringnum():
    return([ord(x)-ord('a') for x in input()])
def inputmatrixchar(rows):
    arr2d = [[j for j in input().strip()] for i in range(rows)]
    return arr2d
def inputmatrixint(rows):
    arr2d = []
    for _ in range(rows):
        arr2d.append([int(i) for i in input().split()])
    return arr2d

t = int(input())
for q in range(t):
    n, s = inputnums()
    a = inputlist()
    mx = 0
    ind = 0
    ans = 0
    for i in range(n):
        if s >= a[i]:
            if a[i] > mx:
                ind = i
                mx = a[i]
            s -= a[i]
            ans += 1
        else:
            s += mx
            ans -= 1
    if ans == n:
        print(0)
    else:
        print(ind+1)


import sys
import math
import heapq
import collections
def inputnum():
    return(int(input()))
def inputnums():
    return(map(int,input().split()))
def inputlist():
    return(list(map(int,input().split())))
def inputstring():
    return([x for x in input()])
def inputstringnum():
    return([ord(x)-ord('a') for x in input()])
def inputmatrixchar(rows):
    arr2d = [[j for j in input().strip()] for i in range(rows)]
    return arr2d
def inputmatrixint(rows):
    arr2d = []
    for _ in range(rows):
        arr2d.append([int(i) for i in input().split()])
    return arr2d

t = int(input())
for q in range(t):
    n, s = inputnums()
    a = inputlist()
    mx = 0
    ind = 0
    ans = 0
    for i in range(n):
        if a[i] > mx:
            ind = i
            mx = a[i]
        if s >= a[i]:
            s -= a[i]
            ans += 1
        else:
            s += mx
            ans -= 1
    if ans == n:
        print(0)
    else:
        print(ind+1)


import sys
import math
import heapq
import collections
def inputnum():
    return(int(input()))
def inputnums():
    return(map(int,input().split()))
def inputlist():
    return(list(map(int,input().split())))
def inputstring():
    return([x for x in input()])
def inputstringnum():
    return([ord(x)-ord('a') for x in input()])
def inputmatrixchar(rows):
    arr2d = [[j for j in input().strip()] for i in range(rows)]
    return arr2d
def inputmatrixint(rows):
    arr2d = []
    for _ in range(rows):
        arr2d.append([int(i) for i in input().split()])
    return arr2d

t = int(input())
for q in range(t):
    n, s = inputnums()
    a = inputlist()
    mx = 0
    ind = 0
    ans = 0
    done = False
    for i in range(n):
        if not done and a[i] > mx:
            ind = i
            mx = a[i]
        if s >= a[i]:
            s -= a[i]
            ans += 1
        elif not done:
            done = True
            s += mx
            ans -= 1
    if ans == n:
        print(0)
    else:
        print(ind+1)


# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class BIT:

    def __init__(self, n):
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    def get(self, l, r=None):
        if r is None: r = l + 1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

    def bisearch_fore(self, l, r, x):
        l_sm = self.sum(l-1)
        ok = r + 1
        ng = l - 1
        while ng+1 < ok:
            mid = (ok+ng) // 2
            if self.sum(mid) - l_sm >= x:
                ok = mid
            else:
                ng = mid
        if ok != r + 1:
            return ok
        else:
            return INF

    def bisearch_back(self, l, r, x):
        r_sm = self.sum(r)
        ok = l - 1
        ng = r + 1
        while ok+1 < ng:
            mid = (ok+ng) // 2
            if r_sm - self.sum(mid-1) >= x:
                ok = mid
            else:
                ng = mid
        if ok != l - 1:
            return ok
        else:
            return -INF

for _ in range(INT()):
    N, K = MAP()
    A = LIST()

    if sum(A) <= K:
        print(0)
        continue

    bit = BIT(N)
    for i, a in enumerate(A):
        bit.add(i, a)
    mx = 0
    for i in range(N):
        bit.add(i, -A[i])
        idx = bit.bisearch_fore(0, N-1, K+1)
        if idx > mx:
            mx = idx
            ans = i + 1
        bit.add(i, A[i])
    print(ans)


# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class BIT:

    def __init__(self, n):
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    def get(self, l, r=None):
        if r is None: r = l + 1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

    def bisearch_back(self, l, r, x):
        r_sm = self.sum(r)
        ok = l - 1
        ng = r + 1
        while ok+1 < ng:
            mid = (ok+ng) // 2
            if r_sm - self.sum(mid-1) >= x:
                ok = mid
            else:
                ng = mid
        if ok != l - 1:
            return ok
        else:
            return -1

    def bisearch_fore(self, l, r, x):
        l_sm = self.sum(l-1)
        ok = r + 1
        ng = l - 1
        while ng+1 < ok:
            mid = (ok+ng) // 2
            if self.sum(mid) - l_sm >= x:
                ok = mid
            else:
                ng = mid
        if ok != r + 1:
            return ok
        else:
            return -1

for _ in range(INT()):
    N, K = MAP()
    A = LIST()

    if sum(A) <= K:
        print(0)
        continue

    bit = BIT(N)
    for i, a in enumerate(A):
        bit.add(i, a)
    mx = 0
    for i in range(N):
        bit.add(i, -A[i])
        idx = bit.bisearch_fore(0, N-1, K+1)
        if idx == -1:
            mx = INF
            ans = i + 1
        elif idx > mx:
            mx = idx
            ans = i + 1
        bit.add(i, A[i])
    print(ans)


# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

class BIT:

    def __init__(self, n):
        nv = 1
        while nv < n:
            nv *= 2
        self.size = nv
        self.tree = [0] * nv

    def sum(self, i):
        s = 0
        i += 1
        while i > 0:
            s += self.tree[i-1]
            i -= i & -i
        return s

    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i-1] += x
            i += i & -i

    def get(self, l, r=None):
        if r is None: r = l + 1
        res = 0
        if r: res += self.sum(r-1)
        if l: res -= self.sum(l-1)
        return res

    def bisearch_back(self, l, r, x):
        r_sm = self.sum(r)
        ok = l - 1
        ng = r + 1
        while ok+1 < ng:
            mid = (ok+ng) // 2
            if r_sm - self.sum(mid-1) >= x:
                ok = mid
            else:
                ng = mid
        if ok != l - 1:
            return ok
        else:
            return -1

    def bisearch_fore(self, l, r, x):
        l_sm = self.sum(l-1)
        ok = r + 1
        ng = l - 1
        while ng+1 < ok:
            mid = (ok+ng) // 2
            if self.sum(mid) - l_sm >= x:
                ok = mid
            else:
                ng = mid
        if ok != r + 1:
            return ok
        else:
            return -1

for _ in range(INT()):
    N, K = MAP()
    A = LIST()

    if sum(A) <= K:
        print(0)
        continue

    bit = BIT(N)
    for i, a in enumerate(A):
        bit.add(i, a)
    mx = 0
    for i in range(N):
        bit.add(i, -A[i])
        idx = bit.bisearch_fore(0, N-1, K+1)
        if idx > mx:
            mx = idx
            ans = i + 1
        bit.add(i, A[i])
    print(ans)


t = int(input())
while t:
    t += -1
    n, s = map(int, input().split())
    l = list(map(int, input().split()))
    m = l[0]
    tem = 0
    ans = 0
    check = 0
    ind = 0
    i2 = 0
    i3 = 0
    for i in range(n):
        if l[i] > m:
            m = l[i]
            ind = i
        tem += l[i]
        if tem >= s and check == 0:
            tem -= m
            ans = ind + 1
            check = 1
            i2 = i
        if tem >= s and check == 1:
            i3 = i
            break
    if i3 == i2 + 1: print(0)
    else: print(ans)


t = int(input())
while t:
    t += -1
    n, s = map(int, input().split())
    l = list(map(int, input().split()))
    m = l[0]
    ans = 1
    tem = 0
    ind = 0
    for i in range(n):
        if l[i] >= m:
            m = l[i]
            ans = i + 1
        tem += l[i]
        if tem >= s:
            ind = i + 1
            break
    if ind <= n - 1:
        if l[ind] >= m: print(0)
        else: print(ans)
    else: print(0)


t = int(input())
while t:
    t += -1
    n, s = map(int, input().split())
    l = list(map(int, input().split()))
    m = l[0]
    ans = 1
    tem = 0
    ind = -1
    for i in range(n):
        if l[i] >= m:
            m = l[i]
            ans = i + 1
        tem += l[i]
        if tem >= s:
            ind = i + 1
            break
    if ind == -1: print(0)
    elif ind <= n - 1:
        if l[ind] >= m: print(0)
        else: print(ans)
    else: print(0)


t = int(input())
while t:
    t += -1
    n, s = map(int, input().split())
    l = list(map(int, input().split()))
    m = l[0]
    ans = 0
    tem = 0
    ind = 0
    for i in range(n):
        if l[i] > m:
            m = l[i]
            ans = i + 1
        tem += l[i]
        if tem >= s:
            ind = i + 1
            break
    if ind <= n - 1:
        if l[ind] >= m: print(0)
        else: print(ans)
    else: print(0)


t = int(input())
while t:
    t += -1
    n, s = map(int, input().split())
    l = list(map(int, input().split()))
    m = l[0]
    ans = 0
    tem = 0
    ch = 0
    for i in range(n):
        if l[i] > m and ch == 0:
            m = l[i]
            ans = i + 1
        tem += l[i]
        if tem > s and ch == 0:
            tem = tem - m
            ch = 1
        if tem >= s and ch == 1:
            break
    print(ans)


t = int(input())
while t:
    t += -1
    n, s = map(int, input().split())
    l = list(map(int, input().split()))
    m = l[0]
    ans = 1
    tem = 0
    ind = 0
    for i in range(n):
        if l[i] > m:
            m = l[i]
            ans = i + 1
        tem += l[i]
        if tem > s:
            ind = i + 1
            break
    if ind <= n - 1:
        if l[ind] >= m: print(0)
        else: print(ans)
    else: print(0)


t = int(input())
while t:
    t += -1
    n, s = map(int, input().split())
    l = list(map(int, input().split()))
    m = l[0]
    ans = 1
    tem = 0
    ind = 0
    for i in range(n):
        if l[i] > m:
            m = l[i]
            ans = i + 1
        tem += l[i]
        if tem >= s:
            ind = i + 1
            break
    if ind <= n - 1:
        if l[ind] >= m: print(0)
        else: print(ans)
    else: print(0)


t = int(input())
for _ in range(t):

    n,k  = map(int,input().split())
    a = list(map(int,input().split()))

    i = 0
    time = 0
    skip = -1
    while i < n:
        if i+1 < n:
            if a[i] <= k:
                if  a[i] > a[i + 1]:
                    if skip == -1:
                        skip = i
                    elif a[skip] <= k:
                        if  a[skip]  <= a[i] :
                            k -= a[skip]
                            skip = i
                else:
                    time += a[i]
                    k -= a[i]
            elif skip != -1 and a[skip] <= k:
                k -= a[skip]
                skip = i
            elif skip == -1:
                skip = i
            else:
                break

        else:
            if a[n-1] > k and skip == -1:
                skip = n - 1
        i += 1

    print(skip + 1)


t = int(input())
for _ in range(t):

    n,k  = map(int,input().split())
    a = list(map(int,input().split()))

    i = 0
    time = 0
    skip = -1
    while i < n:
        if i+1 < n:
            if a[i] <= k:
                if  a[i] > a[i + 1]:
                    if skip == -1:
                        skip = i
                    elif a[skip] <= k:
                        if  a[skip]  <= a[i] :
                            k -= a[skip]
                            skip = i
                else:
                    time += a[i]
                    k -= a[i]
            elif skip != -1 and a[skip] <= k:
                k -= a[skip]
                skip = i
        else:
            if a[n-1] > k and skip == -1:
                skip = n - 1
        i += 1

    print(skip + 1)


t = int(input())
for _ in range(t):

    n,k  = map(int,input().split())
    a = list(map(int,input().split()))

    i = 0
    count = 1
    time = 0
    skip = -1
    while i < n:
        if i+1 < n:
            if a[i] <= k:
                if  a[i] > a[i + 1]:
                    if skip == -1:
                        skip = i
                    elif a[skip] <= k:
                        if  a[skip]  <= a[i] :
                            k -= a[skip]
                            skip = i
                else:
                    time += a[i]
                    k -= a[i]
            elif skip != -1 and a[skip] <= k:
                k -= a[skip]
                skip = i
            elif skip == -1:
                skip = i
                count += 1
            else:
                count += 1

        else:
            if a[n-1] > k and skip == -1:
                skip = n - 1
        i += 1

    if count == n:
        skip = -1
    print(skip + 1)


t = int(input())
for _ in range(t):

    n,k  = map(int,input().split())
    a = list(map(int,input().split()))
    max_index = []
    prefix_array = []
    prefix_array.append(a[0])
    max_elem = 0
    max_index.append(a[0])
    i = 1
    while i < n:
        prefix_array.append((prefix_array[i-1] + a[i]))
        if a[i] > a[max_elem]:
            max_elem = i
        max_index.append(max_elem)
        i += 1

    skipped =  False
    skip = -1
    for i in range(n):
        if prefix_array[i] > k:
            if not skipped:
                skip = max_index[i]
                skipped = True
            elif prefix_array[i] - a[skip] > k:
                break
    print(skip + 1)


t = int(input())
for _ in range(t):

    n,k  = map(int,input().split())
    a = list(map(int,input().split()))
    max_index = []
    prefix_array = []
    prefix_array.append(a[0])
    max_elem = 0
    max_index.append(0)
    i = 1
    while i < n:
        prefix_array.append((prefix_array[i-1] + a[i]))
        if a[i] > a[max_elem]:
            max_elem = i
        max_index.append(max_elem)
        i += 1

    skipped =  False
    skip = -1
    for i in range(n):
        if prefix_array[i] > k:
            if not skipped:
                skip = max_index[i]
                skipped = True
            elif prefix_array[i] - a[skip] > k:
                break
    print(skip + 1)


t = int(input())
for _ in range(t):

    n,k  = map(int,input().split())
    a = list(map(int,input().split()))

    i = 0
    time = 0
    skip = -1
    while i < n:
        if i+1 < n:
            if a[i] <= k:
                if  a[i] > a[i + 1]:
                    if skip == -1:
                        skip = i
                    elif a[skip] <= k:
                        if  a[skip]  <= a[i] :
                            k -= a[skip]
                            skip = i
                else:
                    time += a[i]
                    k -= a[i]
            elif skip != -1 and a[skip] <= k:
                k -= a[skip]
                skip = i
        else:
            if a[n-1] > k and skip == -1:
                skip = a[n-1]
        i += 1

    print(skip + 1)


from bisect import *

for _ in range(int(input())):
    n,s = map(int,input().split())
    l = list(map(int,input().split()))
    m = [0]
    for i in range(1,n):
        if l[m[-1]]<l[i]:m.append(i)
        else:m.append(m[-1])
        l[i] = l[i]+l[i-1]
    idx = bisect_right(l,s)
    ans = 0
    if idx<n:
        if l[idx]>l[m[idx-1]]:
            ans = m[idx-1]+1
    print(ans)


for _ in range(int(input())):
    n,s = map(int,input().split())
    l = list(map(int,input().split()))
    last,curr = [l[0],1],[l[0],1]
    ans=0
    for i in range(1,n):
        curr = [l[i],i+1]
        l[i] = l[i]+l[i-1]
        if l[i]>s:
            if curr[0]<last[0]:
                ans= last[1]
                break
        last = max(curr,last)
    print(ans)


from bisect import *

for _ in range(int(input())):
    n,s = map(int,input().split())
    l = list(map(int,input().split()))
    m = [0]
    for i in range(1,n):
        if l[m[-1]]<l[i]:m.append(i)
        else:m.append(m[-1])
        l[i] = l[i]+l[i-1]
    idx = bisect_right(l,s)
    ans = 0
    if idx<n:
        if l[idx]-l[m[idx-1]]<=s:
            ans = m[idx-1]+1
    print(ans)


T = int(input())

for _ in range(T):
  n,s = map(int, input().split())
  arr = [int(x) for x in input().split()]
  tot = sum(arr)
  if tot <= s:
    print(0)
  else:
    hi = 0
    idx = 0
    for i,x in enumerate(arr):
      if s + hi - x < 0:
        break
      if x > hi:
        idx = i
        hi = x
      s -= x
    print(idx+1)


T = int(input())

for _ in range(T):
  n,s = map(int, input().split())
  arr = [int(x) for x in input().split()]
  tot = sum(arr)
  if tot <= s:
    print(0)
  else:
    hi = 0
    idx = 0
    tot = s
    cnt = 0
    for i,x in enumerate(arr):
      tmp = max(hi, x)
      tot -= x
      cnt += 1
      if tot + tmp < 0:
        break
      if x > hi:
        idx = i
        hi = x
    cnt2 = 0
    tot = s
    for i,x in enumerate(arr):
      tot -= x
      if tot < 0:
        cnt2 = i
        break
    if cnt > cnt2:
      print(idx+1)
    else:
      print(0)


T = int(input())

for _ in range(T):
  n,s = map(int, input().split())
  arr = [int(x) for x in input().split()]
  tot = sum(arr)
  if tot <= s:
    print(0)
  else:
    hi = 0
    idx = 0
    tot = s
    cnt = 0
    for i,x in enumerate(arr):
      if tot + hi - x < 0:
        break
      if x > hi:
        idx = i
        hi = x
      tot -= x
      cnt += 1
    cnt2 = 0
    tot = s
    for i,x in enumerate(arr):
      tot -= x
      if tot < 0:
        cnt2 = i
        break
    if cnt > cnt2:
      print(idx+1)
    else:
      print(0)


T = int(input())

for _ in range(T):
  n,s = map(int, input().split())
  arr = [int(x) for x in input().split()]
  tot = sum(arr)
  if tot <= s:
    print(0)
  else:
    hi = 0
    idx = 0
    tot = s
    cnt = 0
    for i,x in enumerate(arr):
      if x > hi:
        idx = i
        hi = x
      tot -= x
      cnt += 1
      if tot + hi < 0:
        break
    cnt2 = 0
    tot = s
    for i,x in enumerate(arr):
      tot -= x
      if tot < 0:
        cnt2 = i
        break
    if cnt > cnt2:
      print(idx+1)
    else:
      print(0)


testcases=int(input())
for k in range(testcases):
    numbers,seconds=map(int,input().split( ))
    numberlist=list(map(int,input().split( )))
    greatest=0
    greatestindex=0
    adjustedsecondscounter=seconds
    countervar=0
    while adjustedsecondscounter>0 and countervar<=numbers-1:
        if numberlist[countervar]>greatest and (adjustedsecondscounter-greatest)>0:
            adjustedsecondscounter+=-greatest
            greatest=numberlist[countervar]
            greatestindex=countervar
        elif numberlist[countervar]<adjustedsecondscounter:
            adjustedsecondscounter+=-numberlist[countervar]
        elif numberlist[countervar]>adjustedsecondscounter and numberlist[countervar]<greatest:
            countervar=numbers
        runningsum+=numberlist[countervar]
        countervar+=1
    if runningsum<=seconds:
        print(0)
    else:
        print(greatestindex+1)


testcases=int(input())
for k in range(testcases):
    numbers,seconds=map(int,input().split( ))
    numberlist=list(map(int,input().split( )))
    greatest=0
    greatestindex=0
    adjustedsecondscounter=seconds
    countervar=0
    changesmade=False
    while adjustedsecondscounter>0 and countervar<=numbers-1:
        if numberlist[countervar]>greatest and (adjustedsecondscounter-greatest)>0:
            adjustedsecondscounter+=-greatest
            greatest=numberlist[countervar]
            greatestindex=countervar
            changesmade=True
        elif numberlist[countervar]<adjustedsecondscounter:
            adjustedsecondscounter+=-numberlist[countervar]
        elif numberlist[countervar]>adjustedsecondscounter and numberlist[countervar]<greatest:
            countervar=numbers
        countervar+=1
    if changesmade==True:
        print(greatestindex+1)
    else:
        print(0)


testcases=int(input())
for k in range(testcases):
    numbers,seconds=map(int,input().split( ))
    numberlist=list(map(int,input().split( )))
    greatest=0
    greatestindex=0
    adjustedsecondscounter=seconds
    countervar=0
    runningsum=0
    while adjustedsecondscounter>0 and countervar<=numbers-1:
        if numberlist[countervar]>greatest and (adjustedsecondscounter-greatest)>=0:
            adjustedsecondscounter+=-greatest
            greatest=numberlist[countervar]
            greatestindex=countervar
        elif numberlist[countervar]<adjustedsecondscounter:
            adjustedsecondscounter+=-numberlist[countervar]
        elif numberlist[countervar]>adjustedsecondscounter and numberlist[countervar]<greatest:
            countervar=numbers
        runningsum+=numberlist[countervar]
        countervar+=1
    if runningsum<=seconds:
        print(0)
    else:
        print(greatestindex+1)


testcases=int(input())
for k in range(testcases):
    numbers,seconds=map(int,input().split( ))
    numberlist=list(map(int,input().split( )))
    greatest=0
    greatestindex=0
    adjustedsecondscounter=seconds
    countervar=0
    while adjustedsecondscounter>0 and countervar<=numbers-1:
        if numberlist[countervar]>greatest and (adjustedsecondscounter-greatest)>0:
            adjustedsecondscounter+=-greatest
            greatest=numberlist[countervar]
            greatestindex=countervar
        elif numberlist[countervar]<adjustedsecondscounter:
            adjustedsecondscounter+=-numberlist[countervar]
        elif numberlist[countervar]>adjustedsecondscounter and numberlist[countervar]<greatest:
            countervar=numbers
        running+=numberlist[countervar]
        countervar+=1
    if runningsum<=seconds:
        print(0)
    else:
        print(greatestindex+1)


testcases=int(input())
for k in range(testcases):
    numbers,seconds=map(int,input().split( ))
    numberlist=list(map(int,input().split( )))
    greatest=numberlist[0]
    greatestindex=0
    adjustedsecondscounter=seconds
    countervar=1
    while adjustedsecondscounter>0 and countervar<=numbers-1:
        if numberlist[countervar]>greatest and (adjustedsecondscounter-greatest)>0:
            adjustedsecondscounter+=-greatest
            greatest=numberlist[countervar]
            greatestindex=countervar
        elif numberlist[countervar]<adjustedsecondscounter:
            adjustedsecondscounter+=-numberlist[countervar]
        elif numberlist[countervar]>adjustedsecondscounter and numberlist[countervar]<greatest:
            countervar=numbers
        countervar+=1
    if greatestindex==0:
        print(0)
    else:
        print(greatestindex+1)


testcases=int(input())
for k in range(testcases):
    numbers,seconds=map(int,input().split( ))
    numberlist=list(map(int,input().split( )))
    greatest=numberlist[0]
    greatestindex=0
    adjustedsecondscounter=seconds
    countervar=1
    while adjustedsecondscounter>0 and countervar<=numbers-1:
        if numberlist[countervar]>greatest and (adjustedsecondscounter-greatest)>0:
            adjustedsecondscounter+=-greatest
            greatest=numberlist[countervar]
            greatestindex=countervar
        elif numberlist[countervar]<adjustedsecondscounter:
            adjustedsecondscounter+=-numberlist[countervar]
        elif numberlist[countervar]>adjustedsecondscounter and numberlist[countervar]<greatest:
            countervar=numbers
        countervar+=1
    print(greatestindex+1)


testcases=int(input())
for k in range(testcases):
    numbers,seconds=map(int,input().split( ))
    numberlist=list(map(int,input().split( )))
    greatest=0
    greatestindex=0
    adjustedsecondscounter=seconds
    countervar=0
    runningsum=0
    while adjustedsecondscounter>0 and countervar<=numbers-1:
        if numberlist[countervar]>greatest and (adjustedsecondscounter-greatest)>0:
            adjustedsecondscounter+=-greatest
            greatest=numberlist[countervar]
            greatestindex=countervar
        elif numberlist[countervar]<adjustedsecondscounter:
            adjustedsecondscounter+=-numberlist[countervar]
        elif numberlist[countervar]>adjustedsecondscounter and numberlist[countervar]<greatest:
            countervar=numbers
        runningsum+=numberlist[countervar]
        countervar+=1
    if adjustedsecondscounter!=seconds-runningsum:
        print(greatestindex+1)
    else:
        print(0)


import sys
testcases=int(input())
answerlist=[]
for k in range(testcases):
    numbers,seconds=map(int,sys.stdin.readline().split( ))
    numberlist=list(map(int,sys.stdin.readline().split( )))
    greatest=0
    greatestindex=0
    adjustedsecondscounter=seconds
    countervar=0
    runningsum=0
    while adjustedsecondscounter>0 and countervar<=(len(numberlist)-1):
        if numberlist[countervar]>greatest and (adjustedsecondscounter-greatest)>=0:
            adjustedsecondscounter+=-greatest
            greatest=numberlist[countervar]
            greatestindex=countervar
        elif numberlist[countervar]<adjustedsecondscounter:
            adjustedsecondscounter+=-numberlist[countervar]
        elif numberlist[countervar]>adjustedsecondscounter and numberlist[countervar]<greatest:
            countervar=numbers
        if countervar<=numbers-1:
            runningsum+=numberlist[countervar]
        countervar+=1
    if runningsum<=seconds:
        answerlist.append(str(0))
    else:
        answerlist.append(str(greatestindex+1))
for l in answerlist:
    sys.stdout.write("\n"+l)


import sys
testcases=int(input())
answerlist=[]
for k in range(testcases):
    numbers,seconds=map(int,sys.stdin.readline().split( ))
    numberlist=list(map(int,sys.stdin.readline().split( )))
    greatest=0
    greatestindex=0
    adjustedsecondscounter=seconds
    countervar=0
    runningsum=0
    while adjustedsecondscounter>0 and countervar<=(len(numberlist)-1):
        if numberlist[countervar]>greatest and (adjustedsecondscounter-greatest)>=0:
            adjustedsecondscounter+=-greatest
            greatest=numberlist[countervar]
            greatestindex=countervar
        elif numberlist[countervar]<adjustedsecondscounter:
            adjustedsecondscounter+=-numberlist[countervar]
        elif numberlist[countervar]>adjustedsecondscounter and numberlist[countervar]<greatest:
            countervar=numbers
        if countervar<=numbers-1:
            runningsum+=numberlist[countervar]
        countervar+=1
    if runningsum<=seconds:
        answerlist.append(str(0))
    else:
        answerlist.append(str(greatedindex+1))
for l in answerlist:
    sys.stdout.write("\n"+l)


testcases=int(input())
for k in range(testcases):
    numbers,seconds=map(int,input().split( ))
    numberlist=list(map(int,input().split( )))
    greatest=numberlist[0]
    greatestindex=0
    adjustedsecondscounter=seconds
    countervar=1
    changesmade=False
    while adjustedsecondscounter>0 and countervar<=numbers-1:
        if numberlist[countervar]>greatest and (adjustedsecondscounter-greatest)>0:
            adjustedsecondscounter+=-greatest
            greatest=numberlist[countervar]
            greatestindex=countervar
            changesmade=True
        elif numberlist[countervar]<adjustedsecondscounter:
            adjustedsecondscounter+=-numberlist[countervar]
        elif numberlist[countervar]>adjustedsecondscounter and numberlist[countervar]<greatest:
            countervar=numbers
        countervar+=1
    if changesmade=True:
        print(greatestindex+1)
    else:
        print(0)


testcases=int(input())
for k in range(testcases):
    numbers,seconds=map(int,input().split( ))
    numberlist=list(map(int,input().split( )))
    greatest=numberlist[0]
    greatestindex=0
    adjustedsecondscounter=seconds
    countervar=1
    changesmade=False
    while adjustedsecondscounter>0 and countervar<=numbers-1:
        if numberlist[countervar]>greatest and (adjustedsecondscounter-greatest)>0:
            adjustedsecondscounter+=-greatest
            greatest=numberlist[countervar]
            greatestindex=countervar
            changesmade=True
        elif numberlist[countervar]<adjustedsecondscounter:
            adjustedsecondscounter+=-numberlist[countervar]
        elif numberlist[countervar]>adjustedsecondscounter and numberlist[countervar]<greatest:
            countervar=numbers
        countervar+=1
    if changesmade==True:
        print(greatestindex+1)
    else:
        print(0)


testcases=int(input())
for k in range(testcases):
    numbers,seconds=map(int,input().split( ))
    numberlist=list(map(int,input().split( )))
    greatest=0
    greatestindex=0
    adjustedsecondscounter=seconds
    countervar=0
    while adjustedsecondscounter>0 and countervar<=numbers-1:
        if numberlist[countervar]>greatest and (adjustedsecondscounter-greatest)>0:
            adjustedsecondscounter+=-greatest
            greatest=numberlist[countervar]
            greatestindex=countervar
            runningsum=numberlist[countervar]
        elif numberlist[countervar]<adjustedsecondscounter:
            adjustedsecondscounter+=-numberlist[countervar]
            runningsum=numberlist[countervar]
        elif numberlist[countervar]>adjustedsecondscounter and numberlist[countervar]<greatest:
            countervar=numbers
        countervar+=1
    if runningsum<=seconds:
        print(0)
    else:
        print(greatestindex+1)


testcases=int(input())
for k in range(testcases):
    numbers,seconds=map(int,input().split( ))
    numberlist=list(map(int,input().split( )))
    greatest=0
    greatestindex=0
    adjustedsecondscounter=seconds
    countervar=0
    runningsum=0
    while adjustedsecondscounter>0 and countervar<=(len(numberlist)-1):
        if numberlist[countervar]>greatest and (adjustedsecondscounter-greatest)>=0:
            adjustedsecondscounter+=-greatest
            greatest=numberlist[countervar]
            greatestindex=countervar
        elif numberlist[countervar]<adjustedsecondscounter:
            adjustedsecondscounter+=-numberlist[countervar]
        elif numberlist[countervar]>adjustedsecondscounter and numberlist[countervar]<greatest:
            countervar=numbers
        if countervar<=numbers-1:
            runningsum+=numberlist[countervar]
        countervar+=1
    if runningsum<=seconds:
        print(0)
    else:
        print(greatestindex+1)


testcases=int(input())
for k in range(testcases):
    numbers,seconds=map(int,input().split( ))
    numberlist=list(map(int,input().split( )))
    greatest=0
    greatestindex=0
    adjustedsecondscounter=seconds
    countervar=0
    runningsum=0
    while adjustedsecondscounter>0 and countervar<=numbers-1:
        if numberlist[countervar]>greatest and (adjustedsecondscounter-greatest)>0:
            adjustedsecondscounter+=-greatest
            greatest=numberlist[countervar]
            greatestindex=countervar
        elif numberlist[countervar]<adjustedsecondscounter:
            adjustedsecondscounter+=-numberlist[countervar]
        elif numberlist[countervar]>adjustedsecondscounter and numberlist[countervar]<greatest:
            countervar=numbers
        runningsum+=numberlist[countervar]
        countervar+=1
    if runningsum<=seconds:
        print(0)
    else:
        print(greatestindex+1)


"""
    Satwik_Tiwari ;) .
    25 june , 2020  - Thursday
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase

import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(l,h)
        mid = (l+h)//2
        if(a[mid] == x):
            return mid
        if(a[mid] < x):
            l = mid+1
        else:
            h = mid
    return l

def sieve(a): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    for i in range(3,((10**6)+1),2):
        for j in range(i*i,((10**6)+1),i):
            a[j] = 0
    a[2] = 1 #special left case
    return (a)

def bfs(g,st):
    visited = [0]*(len(g))
    visited[st] = 1
    queue = []
    queue.append(st)
    new = []
    while(len(queue) != 0):
        s = queue.pop()
        new.append(s)
        for i in g[s]:
            if(visited[i] == 0):
                visited[i] = 1
                queue.append(i)
    return new

def solve():
    n,ss = sep()
    a = lis()
    m = 0
    if(sum(a) <= ss):
        print(0)
        return

    summ = 0
    for i in range(0,n):
        m = max(m,a[i])
        summ+=a[i]
        ind = i
        if(summ > ss):
            break

    print(a.index(m)+1)
    #chupad ekdum

# testcase(1)
testcase(int(inp()))


"""
    Satwik_Tiwari ;) .
    25 june , 2020  - Thursday
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase

import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(l,h)
        mid = (l+h)//2
        if(a[mid] == x):
            return mid
        if(a[mid] < x):
            l = mid+1
        else:
            h = mid
    return l

def sieve(a): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    for i in range(3,((10**6)+1),2):
        for j in range(i*i,((10**6)+1),i):
            a[j] = 0
    a[2] = 1 #special left case
    return (a)

def bfs(g,st):
    visited = [0]*(len(g))
    visited[st] = 1
    queue = []
    queue.append(st)
    new = []
    while(len(queue) != 0):
        s = queue.pop()
        new.append(s)
        for i in g[s]:
            if(visited[i] == 0):
                visited[i] = 1
                queue.append(i)
    return new

def solve():
    n,s = sep()
    a = lis()
    pre = []
    for i in range(0,n):
        if(i==0):
            pre.append(a[i])
        else:
            pre.append(a[i] + pre[i-1])

    # print(pre)
    d = {}
    for i in range(0,n):
        d[pre[i]] = 1

    ind = bl(pre,s)
    if(ind == n):
        print(n)
        return

    # print('lol')
    ans = 0
    ll = ind+1

    for i in range(0,n):
        # print(s+a[i])
        temp = bl(pre,s+a[i])
        if(d.get(s+a[i]) == None):
            temp-=1
        # print(temp,'lol')
        if(temp > ll):
            ans = i+1
            ll = max(ll,temp)

        # print(ans,'ans')
    print(ans)

# testcase(1)
testcase(int(inp()))


"""
    Satwik_Tiwari ;) .
    25 june , 2020  - Thursday
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase

import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(l,h)
        mid = (l+h)//2
        if(a[mid] == x):
            return mid
        if(a[mid] < x):
            l = mid+1
        else:
            h = mid
    return l

def sieve(a): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    for i in range(3,((10**6)+1),2):
        for j in range(i*i,((10**6)+1),i):
            a[j] = 0
    a[2] = 1 #special left case
    return (a)

def bfs(g,st):
    visited = [0]*(len(g))
    visited[st] = 1
    queue = []
    queue.append(st)
    new = []
    while(len(queue) != 0):
        s = queue.pop()
        new.append(s)
        for i in g[s]:
            if(visited[i] == 0):
                visited[i] = 1
                queue.append(i)
    return new

def solve():
    n,s = sep()
    a = lis()
    pre = []
    for i in range(0,n):
        if(i==0):
            pre.append(a[i])
            continue
        pre.append(pre[i-1] + a[i])

    ptr = 0
    m = 0
    for i in range(0,n):
        if(pre[i] <= s):
            m = max(m,a[i])
            # print(m,'m')
            continue
        else:
            ptr = i
            break
    ans = ptr
    s = 0
    ptr-=1
    while(ptr+1 < n and s+a[ptr+1]<=m):
        ptr+=1
        s += a[ptr]
    ptr+=1
    # print(ans,ptr+1)
    if(ptr-ans > 1):
        print(a.index(m)+1)
    else:
        print(0)

# testcase(1)
testcase(int(inp()))


"""
    Satwik_Tiwari ;) .
    25 june , 2020  - Thursday
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase

import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(l,h)
        mid = (l+h)//2
        if(a[mid] == x):
            return mid
        if(a[mid] < x):
            l = mid+1
        else:
            h = mid
    return l

def sieve(a): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    for i in range(3,((10**6)+1),2):
        for j in range(i*i,((10**6)+1),i):
            a[j] = 0
    a[2] = 1 #special left case
    return (a)

def bfs(g,st):
    visited = [0]*(len(g))
    visited[st] = 1
    queue = []
    queue.append(st)
    new = []
    while(len(queue) != 0):
        s = queue.pop()
        new.append(s)
        for i in g[s]:
            if(visited[i] == 0):
                visited[i] = 1
                queue.append(i)
    return new

def solve():
    n,ss = sep()
    a = lis()
    pre = []
    for i in range(0,n):
        if(i==0):
            pre.append(a[i])
            continue
        pre.append(pre[i-1] + a[i])

    ptr = 0
    m = 0
    for i in range(0,n):
        if(pre[i] <= ss):
            m = max(m,a[i])
            # print(m,'m')
            continue
        else:
            ptr = i
            break

    ans = ptr
    cnt = 0
    s = 0
    # print(pre)
    rem = ss - pre[ans-1]
    # print(rem)
    for i in range(ptr,n):
        s += a[i]
        if(s<=m+rem):
            cnt+=1
        else:
            break
    # print(ans,cnt)
    new = 0
    count = 0
    for i in range(0,n):
        if(i==ans):
            continue
        else:
            if(new+a[i]<=ss):
                count+=1
                new+=a[i]
            else:
                break
    # print(count,ans,cnt)
    if(count > ans+cnt-1):
        print(ans+1)
    elif(cnt>1):

        print(a.index(m)+1)
    else:
        print(0)

# testcase(1)
testcase(int(inp()))


"""
    Satwik_Tiwari ;) .
    25 june , 2020  - Thursday
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase

import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(l,h)
        mid = (l+h)//2
        if(a[mid] == x):
            return mid
        if(a[mid] < x):
            l = mid+1
        else:
            h = mid
    return l

def sieve(a): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    for i in range(3,((10**6)+1),2):
        for j in range(i*i,((10**6)+1),i):
            a[j] = 0
    a[2] = 1 #special left case
    return (a)

def bfs(g,st):
    visited = [0]*(len(g))
    visited[st] = 1
    queue = []
    queue.append(st)
    new = []
    while(len(queue) != 0):
        s = queue.pop()
        new.append(s)
        for i in g[s]:
            if(visited[i] == 0):
                visited[i] = 1
                queue.append(i)
    return new

def solve():
    n,ss = sep()
    a = lis()
    m = 0
    sum = 0
    for i in range(0,n):
        m = max(m,a[i])
        sum+=a[i]
        ind = i
        if(sum > ss):
            break
    cnt = 0
    s = 0
    for i in range(ind+1,n):
        s+=a[i]
        if(s > m):
            break
        cnt+=1

    if(cnt>0):
        print(a.index(m) + 1)
    else:
        if(a.index(m) == ind):
            print(0)
        else:
            print(a.index(m)+1)

# testcase(1)
testcase(int(inp()))


"""
    Satwik_Tiwari ;) .
    25 june , 2020  - Thursday
"""

#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function

from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase

import bisect
from heapq import *
from math import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned

#==============================================================================================

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

#===============================================================================================
#some shortcuts

mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n")  #as stdout.write always print sring.
def testcase(t):
    for p in range(t):
        solve()
def printlist(a) :
    for p in range(0,len(a)):
        out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
    ans = 1
    while(b>0):
        if(b%2==1):
            ans*=a
        a*=a
        b//=2
    return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) : # Check Prime Number or not
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#===============================================================================================
# code here ;))
def bs(a,l,h,x):
    while(l<h):
        # print(l,h)
        mid = (l+h)//2
        if(a[mid] == x):
            return mid
        if(a[mid] < x):
            l = mid+1
        else:
            h = mid
    return l

def sieve(a): #O(n loglogn) nearly linear
    #all odd mark 1
    for i in range(3,((10**6)+1),2):
        a[i] = 1
    #marking multiples of i form i*i 0. they are nt prime
    for i in range(3,((10**6)+1),2):
        for j in range(i*i,((10**6)+1),i):
            a[j] = 0
    a[2] = 1 #special left case
    return (a)

def bfs(g,st):
    visited = [0]*(len(g))
    visited[st] = 1
    queue = []
    queue.append(st)
    new = []
    while(len(queue) != 0):
        s = queue.pop()
        new.append(s)
        for i in g[s]:
            if(visited[i] == 0):
                visited[i] = 1
                queue.append(i)
    return new

def solve():
    n,ss = sep()
    a = lis()
    m = 0
    if(sum(a) <= ss):
        print(0)
        return

    summ = 0

    for i in range(0,n):
        m = max(m,a[i])
        summ+=a[i]
        ind = i
        if(summ > ss):
            break
    cnt = 0
    s = 0
    for i in range(ind+1,n):
        s+=a[i]
        if(s > m):
            break
        cnt+=1

    print(a.index(m)+1)

# testcase(1)
testcase(int(inp()))


import os
import sys
from io import BytesIO, IOBase
# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------------------

def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
def toord(c): return ord(c)-ord('a')
def lcm(a, b): return a*b//lcm(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
from bisect import bisect_right

# ------------------------------
# f = open('./input.txt')
# sys.stdin = f

def main():
    for _ in range(N()):
        n, s = RL()
        arr = RLL()
        ma = 0

        sm = [0]
        for i in range(n):
            sm.append(sm[-1]+arr[i])
            if sm[-1]<=s:
                ma = i+1

        res = 0
        for i in range(n):
            now = arr[i] + s
            pos = bisect_right(sm, now)
            if pos-1>ma:
                ma = pos-1
                res = i+1
        print(res)

if __name__ == "__main__":
    main()


import os
import sys
from io import BytesIO, IOBase
# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------------------

def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
def toord(c): return ord(c)-ord('a')
def lcm(a, b): return a*b//lcm(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
from bisect import bisect_right

# # ------------------------------
# f = open('./input.txt')
# sys.stdin = f

def main():
    for _ in range(N()):
        n, s = RL()
        arr = RLL()
        ma = 0

        sm = [0]
        for i in range(n):
            sm.append(sm[-1]+arr[i])
            if sm[-1]<=s:
                ma = i+1

        res = 0
        for i in range(n):
            now = arr[i] + s
            pos = bisect_right(sm, now)
            if pos<i: break
            if pos-1>ma:
                ma = pos-1
                res = i+1

        print(res)

if __name__ == "__main__":
    main()


import os
import sys
from io import BytesIO, IOBase
# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------------------

def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
def toord(c): return ord(c)-ord('a')
def lcm(a, b): return a*b//lcm(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
from bisect import bisect_right

# ------------------------------
# f = open('./input.txt')
# sys.stdin = f

def main():
    for _ in range(N()):
        n, s = RL()
        arr = RLL()
        ma = 0

        sm = [0]
        for i in range(n):
            sm.append(sm[-1]+arr[i])
            if sm[-1]<=s:
                ma = i+1

        if sm[-1]<=s:
            print(0)
            continue

        res = 0
        for i in range(n):
            now = arr[i] + s
            pos = bisect_right(sm, now)
            if pos<i: break
            if pos-1>ma:
                ma = pos-1
                res = i+1

        print(res)

if __name__ == "__main__":
    main()


import os
import sys
from io import BytesIO, IOBase
# region fastio

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# ------------------------------

def RL(): return map(int, sys.stdin.readline().rstrip().split())
def RLL(): return list(map(int, sys.stdin.readline().rstrip().split()))
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
def toord(c): return ord(c)-ord('a')
def lcm(a, b): return a*b//lcm(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush
from bisect import bisect_right

# ------------------------------
f = open('./input.txt')
sys.stdin = f

def main():
    for _ in range(N()):
        n, s = RL()
        arr = RLL()
        ma = 0

        sm = [0]
        for i in range(n):
            sm.append(sm[-1]+arr[i])
            if sm[-1]<=s:
                ma = i+1

        if sm[-1]<=s:
            print(0)
            continue

        res = 0
        for i in range(n):
            now = arr[i] + s
            pos = bisect_right(sm, now)
            if pos<i: break
            if pos-1>ma:
                ma = pos-1
                res = i+1

        print(res)

if __name__ == "__main__":
    main()