//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        bool c = false;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            if(x%2 == 0)
            {
                c = true;
            }
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        auto it3 = a.begin();
        it3++;
        auto it4 = a.end();
        it2--;
        it4--;
        it4--;
        ll ans = (*it)*(*it2);
        if(c == true && *it != 2)
        {
            cout << -1 << endl;
            continue;
        }
        ll ans2 = (*it3)*(*it4);
        if(ans2 != ans)
        {
            cout << -1 << endl;
            continue;
        }
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        if(*it >= 100000 && n != 1)
        {
            cout << -1 << endl;
            continue;
        }
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        bool c = false;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        bool an = false;
        for(int i = 0; i < n/2; i++)
        {
            it++;
            it2--;
            ll ans2 = (*it)*(*it2);
            if(ans2 != ans)
            {
                cout << -1;
                an = true;
                break;
            }
        }
        if(an == true)
        {
            continue;
        }
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007

ll countDivisors(ll n)
{
    ll cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            if (n / i == i)
                cnt++;

            else
                cnt = cnt + 2;
        }
    }
    return cnt;
}

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        bool an = false;
        if(a.size() != countDivisors(ans)-2)
        {
            cout << -1 << endl;
            continue;
        }
        if(n == 1)
        {
            cout << (*it)*(*it) << endl;
            continue;
        }
        for(int i = 0; i < n/2; i++)
        {
            it++;
            it2--;
            ll ans2 = (*it)*(*it2);
            if(ans2 != ans)
            {
                cout << -1 << endl;
                an = true;
                break;
            }
        }
        if(an == true)
        {
            continue;
        }
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        if(*it >= 1000000 && n != 1)
        {
            cout << -1 << endl;
            continue;
        }
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        bool c = false;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            if(x%2 == 0)
            {
                c = true;
            }
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        if(c == true && *it != 2)
        {
            cout << -1 << endl;
            continue;
        }
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007

ll countDivisors(ll n)
{
    ll cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++) {
        if (n % i == 0) {
            if (n / i == i)
                cnt++;

            else
                cnt = cnt + 2;
        }
    }
    return cnt;
}

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        bool an = false;
        if(n == 1)
        {
            cout << (*it)*(*it) << endl;
            continue;
        }
        if(a.size() != countDivisors(ans)-2)
        {
            cout << -1 << endl;
            continue;
        }
        for(int i = 0; i < n/2; i++)
        {
            it++;
            it2--;
            ll ans2 = (*it)*(*it2);
            if(ans2 != ans)
            {
                cout << -1 << endl;
                an = true;
                break;
            }
        }
        if(an == true)
        {
            continue;
        }
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        bool c = false;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        bool an = false;
        if(n == 1)
        {
            cout << (*it)*(*it) << endl;
            continue;
        }
        for(int i = 0; i < n/2; i++)
        {
            it++;
            it2--;
            ll ans2 = (*it)*(*it2);
            if(ans2 != ans)
            {
                cout << -1 << endl;
                an = true;
                break;
            }
        }
        if(an == true)
        {
            continue;
        }
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        bool c = false;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        bool an = false;
        for(int i = 0; i <= n/2; i++)
        {
            it++;
            it2--;
            ll ans2 = (*it)*(*it2);
            if(ans2 != ans)
            {
                cout << -1 << endl;
                an = true;
                break;
            }
        }
        if(an == true)
        {
            continue;
        }
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        if(*it >= 20)
        {
            cout << -1 << endl;
            continue;
        }
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        if(*it >= 10000 && n != 1)
        {
            cout << -1 << endl;
            continue;
        }
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        bool c = false;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            if(x%2 == 0)
            {
                c = true;
            }
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        if(c == true && *it != 2)
        {
            cout << -1 << endl;
            continue;
        }
        ll ans2 = 0;
        if(n >= 3)
        {
            auto it4 = a.end();
            it4--;
            it4--;
            auto it3 = a.begin();
            it3++;
            ans2 = (*it3)*(*it4);
        }
        if(ans2 != ans && n >= 4)
        {
            cout << -1 << endl;
            continue;
        }
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        if(*it >= 1000 && n != 1)
        {
            cout << -1 << endl;
            continue;
        }
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        if(*it >= 900000 && n != 1)
        {
            cout << -1 << endl;
            continue;
        }
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        bool c = false;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            if(x%2 == 0)
            {
                c = true;
            }
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        bool an = false;
        if(c == true && *it != 2)
        {
            cout << -1 << endl;
            continue;
        }
        if(n == 1)
        {
            cout << (*it)*(*it) << endl;
            continue;
        }
        for(int i = 0; i < n/2; i++)
        {
            it++;
            it2--;
            ll ans2 = (*it)*(*it2);
            if(ans2 != ans)
            {
                cout << -1 << endl;
                an = true;
                break;
            }
        }
        if(an == true)
        {
            continue;
        }
        cout << ans << endl;
    }
}


//ssenseeeeeeeeeeeeeeeeeeeeeeeeeeeee
#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
typedef unsigned long long ull;
#define MX 1000000000
#define endl '\n'
#define startt ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fr first
#define sc second
#define MOD 1000000007
int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n;
        cin >> n;
        set<ll> a;
        int x;
        bool c = false;
        for(int i = 0; i < n; i++)
        {
            cin >> x;
            a.insert(x);
        }
        auto it = a.begin();
        auto it2 = a.end();
        it2--;
        ll ans = (*it)*(*it2);
        bool an = false;
        if(n == 1)
        {
            cout << (*it)*(*it) << endl;
            continue;
        }
        for(int i = 0; i <= n/2; i++)
        {
            it++;
            it2--;
            ll ans2 = (*it)*(*it2);
            if(ans2 != ans)
            {
                cout << -1 << endl;
                an = true;
                break;
            }
        }
        if(an == true)
        {
            continue;
        }
        cout << ans << endl;
    }
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define mst(a) memset(a,0,sizeof(a))

const int max_n=300+5;
const int max_d=1e6+5;

int t,n,d[max_n];
int vis[max_d];

int main()
{
	cin>>t;
	while(t--)
	{
		mst(vis);
		mst(d);
		cin>>n;
		for(int i=0;i<n;i++)
		{
			cin>>d[i];
			vis[d[i]]=1;
		}
		sort(d,d+n);
		LL pd=d[0]*d[n-1],flag=0;
		for(int i=0;i<n;i++)
			if(pd!=d[i]*d[n-i-1])
			{
			 	flag=1;
				break;
			}
		if(flag==1)
		{
			printf("-1\n");
			continue;
		}
		if(flag==0)
		{
			for(int i=2;i*i<=pd;i++)
			{
				if(pd%i==0)
				{
					if(vis[i]!=1 || vis[pd/i]!=1)
					{
						printf("-1\n");
						flag=1;
						goto out;
					}
				}
			}
		}
		out:;
		if(flag==0) cout<<pd<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define mst(a) memset(a,0,sizeof(a))

const int max_n=300+5;
const int max_d=1e6+5;

LL t,n,d[max_n];
LL vis[max_d];

int main()
{
	cin>>t;
	while(t--)
	{
		mst(vis);
		mst(d);
		cin>>n;
		for(LL i=0;i<n;i++)
		{
			cin>>d[i];
			vis[d[i]]=1;
		}
		sort(d,d+n);

		LL pd = d[0]*d[n-1],flag=0;

		for(LL i=0;i<n;i++)
			if(pd!=d[i]*d[n-i-1])
			 	flag=1;

		if(flag==1)
		{
			printf("-1\n");
			continue;
		}
		if(flag==0)
		{
			for(LL i=2;i*i<=pd;i++)
			{
				if(pd%i==0)
				{
					if(vis[i]!=1 || vis[pd/i]!=1)
					{
						printf("-1\n");
						goto out;
					}
				}
			}
		}
		cout<<pd<<endl;
		out:;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define mst(a) memset(a,0,sizeof(a))

const int max_d=1e6+5;
LL t,n,d[305];
LL vis[max_d];
int main()
{
	cin>>t;
	while(t--)
	{
		mst(d);
		cin>>n;
		for(int i=0;i<n;i++)	cin>>d[i];
		sort(d,d+n);
		LL pd=d[0]*d[n-1],ans=0,flag=0;
		for(LL i=0;i<n;i++)
			if(pd != d[i]*d[n-i-1]) flag=1;
		if(flag==0)
		{
			for(LL i=2;i*i<=pd;i++)
			{
				if(pd%i==0)
				{
					if(i*i==pd) ans+=1;
					else ans+=2;
				}
			}
		}
		if(ans!=n) flag=1;
		if(flag==1)	pd = -1;
		cout<<pd<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define mst(a) memset(a,0,sizeof(a))

const int max_n=300+5;
const int max_d=1e6+5;

LL t,n,d[max_n];
LL vis[max_d];

int main()
{
	cin>>t;
	while(t--)
	{
		mst(vis);
		mst(d);
		cin>>n;
		for(LL i=0;i<n;i++)
		{
			cin>>d[i];
			vis[d[i]]=1;
		}
		sort(d,d+n);
		LL pd=d[0]*d[n-1],flag=0;

		for(LL i=0;i<n;i++)
			if(pd!=d[i]*d[n-i-1]) flag=1;

		if(flag==1)
		{
			printf("-1\n");
			continue;
		}

		if(flag==0)
		{
			for(LL i=2;i*i<=pd;i++)
			{
				if(pd%i==0)
				{
					if(vis[i]!=1 || vis[pd/i]!=1)
					{
						printf("-1\n");
						flag=1;
						goto out;
					}
				}
			}
		}
		out:;
		if(flag==0) cout<<pd<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define mpi map<int, int>
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 100005;
int arr[mxn];
int n;
ll s, all;
void solve(){
    if(all <= s){
        cout << 0 << endl;
        return;
    }
    if(n == 1){
        cout << 0 << endl;
        return;
    }
    ll sum = arr[0];
    int cm = arr[0];
    int mxi = 1;
    bool flag = false;
    for(int i = 1; i < n; i++){
        sum += arr[i];
        if(cm < arr[i]){
            cm = arr[i];
            if(sum - cm <= s){
                mxi = i + 1;
                flag = true;
            }
        }
        if(sum - cm > s) break;
    }
    if(!flag && s < arr[0]){
        cout << 0 << endl;
        return;
    }
    cout << mxi << endl;
}

void read(){
    all = 0;
   cin >> n >> s;
   for(int i = 0; i < n; i++) cin >> arr[i], all += arr[i];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while(T--) read(), solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define mpi map<int, int>
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 100005;
int arr[mxn];
int n;
ll s, all;
void solve(){
    if(all <= s){
        cout << 0 << endl;
        return;
    }
    if(n == 1){
        cout << 0 << endl;
        return;
    }
    if(n == 2){
        if(s < arr[0] && s < arr[1]){
            cout << 0 << endl;
            return;
        }
    }
    ll sum = arr[0];
    int cm = arr[0];
    int mxi = 1;
    bool flag = false;
    for(int i = 1; i < n; i++){
        sum += arr[i];
        if(cm < arr[i]){
            cm = arr[i];
            if(sum - cm <= s){
                mxi = i + 1;
                flag = true;
            }
        }
        if(sum - cm > s) break;
    }
    if(!flag && s < arr[0]){
        cout << 0 << endl;
        return;
    }
    cout << mxi << endl;
}

void read(){
    all = 0;
   cin >> n >> s;
   for(int i = 0; i < n; i++) cin >> arr[i], all += arr[i];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while(T--) read(), solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define mpi map<int, int>
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 100005;
int arr[mxn];
int n;
ll s, all;
void solve(){
    if(all <= s){
        cout << 0 << endl;
        return;
    }
    if(n == 1){
        cout << 0 << endl;
        return;
    }
    ll sum = arr[0];
    int cm = arr[0];
    int mxi = 1;
    bool flag = false;
    for(int i = 1; i < n; i++){
        sum += arr[i];
        if(cm < arr[i] && sum - cm <= s){
            cm = arr[i];
            if(sum - cm <= s){
                mxi = i + 1;
                flag = true;
            }
        }
        if(sum - cm > s) break;
    }
    cout << mxi << endl;
}

void read(){
    all = 0;
   cin >> n >> s;
   for(int i = 0; i < n; i++) cin >> arr[i], all += arr[i];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while(T--) read(), solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define mpi map<int, int>
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 100005;
int arr[mxn];
int n;
ll s, all;
void solve(){
    ll sum = 0;
    int cm = 0;
    int mxi = 0;
    for(int i = 0; i < n; i++){
        if(arr[i] > s){
            if(arr[i] > cm) cout << i + 1 << endl;
            else cout << mxi << endl;
            return;
        }
        sum -= arr[i];
        if(arr[i] > cm){
            cm = arr[i];
            mxi = i + 1;
        }
    }
    cout << 0 << endl;
}

void read(){
    all = 0;
   cin >> n >> s;
   for(int i = 0; i < n; i++) cin >> arr[i], all += arr[i];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while(T--) read(), solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define mpi map<int, int>
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 100005;
int arr[mxn];
int n;
ll s, all;
void solve(){
    if(all <= s || s < arr[0]){
        cout << 0 << endl;
        return;
    }
    ll sum = arr[0];
    int cm = arr[0];
    int mxi = 1;
    for(int i = 1; i < n; i++){
        sum += arr[i];
        if(cm <= arr[i]){
            cm = arr[i];
            if(sum - cm <= s){
                mxi = i + 1;
            }
        }
        if(sum - cm > s) break;
    }
    cout << mxi << endl;
}

void read(){
    all = 0;
   cin >> n >> s;
   for(int i = 0; i < n; i++) cin >> arr[i], all += arr[i];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while(T--) read(), solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define mpi map<int, int>
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 100005;
int arr[mxn];
int n;
ll s, all;
void solve(){
    if(all <= s){
        cout << 0 << endl;
        return;
    }
    ll sum = 0;
    int cm = arr[0];
    int mxi = 1;
    for(int i = 0; i < n; i++){
        if(arr[i] > cm && sum + arr[i] - cm <= s){
            cm = arr[i];
            mxi = i + 1;
        }
        sum += arr[i];
    }
    cout << mxi << endl;
}

void read(){
    all = 0;
   cin >> n >> s;
   for(int i = 0; i < n; i++) cin >> arr[i], all += arr[i];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while(T--) read(), solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define mpi map<int, int>
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 100005;
int arr[mxn];
int n;
ll s, all;
void solve(){
    if(all <= s){
        cout << 0 << endl;
        return;
    }
    ll sum = arr[0];
    int cm = arr[0];
    int mxi = 1;
    bool flag = false;
    for(int i = 1; i < n; i++){
        sum += arr[i];
        if(cm < arr[i]){
            cm = arr[i];
            if(sum - cm <= s){
                mxi = i + 1;
                flag = true;
            }
        }
        if(sum - cm > s) break;
    }
    if(!flag && s < arr[0]){
        cout << 0 << endl;
        return;
    }
    cout << mxi << endl;
}

void read(){
    all = 0;
   cin >> n >> s;
   for(int i = 0; i < n; i++) cin >> arr[i], all += arr[i];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while(T--) read(), solve();
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define mpi map<int, int>
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 100005;
int arr[mxn];
int n;
ll s, all;
void solve(){
    ll sum = 0;
    int cm = 0;
    int mxi = 0;
    for(int i = 0; i < n; i++){
        if(arr[i] > s){
            if(arr[i] > cx) cout << i + 1 << endl;
            else cout << mxi << endl;
            return;
        }
        sum -= arr[i];
        if(arr[i] > cm){
            cm = arr[i];
            mxi = i + 1;
        }
    }
    cout << 0 << endl;
}

void read(){
    all = 0;
   cin >> n >> s;
   for(int i = 0; i < n; i++) cin >> arr[i], all += arr[i];
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int T = 1;
    cin >> T;
    while(T--) read(), solve();
    return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <sstream>

using namespace std;

#define fori(t) for(int i = 0; i < t; ++i)
#define forj(n) for(int j = 0; j < n; ++j)
#define fork(n) for(int k = 0; k < n; ++k)
#define forai(a) for(auto i : a)
#define foraj(a) for(auto j : a)
#define forak(a) for(auto k : a)
#define forp(s, n, d) for(int p = s; p < n; p += d)
#define read cin >>
#define print cout <<
#define fast cin.tie(0); cout.tie(0); std::ios_base::sync_with_stdio(0);
#define pub(a) push_back(a);
#define pob(a) pop_back(a);
#define sorti(a) sort(a.begin(), a.end());
#define sortm(a, n) sort(a, a + n);
#define fi first
#define se second
#define yes print "YES\n";
#define no print "NO\n";
#define ans(a) print a << '\n';

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<long long, long long> llll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long, long long>> vllll;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef pair<char, char> cc;
typedef pair<pair<char, char>, char> ccc;
typedef vector<char> vc;
typedef pair<int, char> ic;
typedef pair<ii, char> iic;

const int INF = 2147483647;
const ll LONGINF = 2147483647 * 1e7;

vector<int> aa;

void solve()
{
    int n, s;
    read n >> s;
    int maxim = 0;
    int t = 0, ind = -1, savedT = -1, maxInd = -1;
    fori(n)
    {
        int a;
        read a;
        t += a;
        if (a > maxim && t <= s)
        {
            maxim = a;
            maxInd = i;
        }
        if (t <= s)
        {
            ind = i + 1;
            savedT = t;
        }
        aa.pub(a);
    }
    if (ind == aa.size()) ans(0)
    else
    {
        int res = ind;
        savedT -= maxim;
        while (savedT <= s)
        {
            savedT += aa[ind];
            ++ind;
        }
        if (res > ind - 1) ans(aa.size())
        else ans(maxInd + 1)
    }
    aa = vector<int>();
}

int main()
{
    fast
    bool mult = true;
    if (mult)
    {
        int t;
        read t;
        while (t--) solve();
    }
    else solve();
}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <sstream>

using namespace std;

#define fori(t) for(int i = 0; i < t; ++i)
#define forj(n) for(int j = 0; j < n; ++j)
#define fork(n) for(int k = 0; k < n; ++k)
#define forai(a) for(auto i : a)
#define foraj(a) for(auto j : a)
#define forak(a) for(auto k : a)
#define forp(s, n, d) for(int p = s; p < n; p += d)
#define read cin >>
#define print cout <<
#define fast cin.tie(0); cout.tie(0); std::ios_base::sync_with_stdio(0);
#define pub(a) push_back(a);
#define pob(a) pop_back(a);
#define sorti(a) sort(a.begin(), a.end());
#define sortm(a, n) sort(a, a + n);
#define fi first
#define se second
#define yes print "YES\n";
#define no print "NO\n";
#define ans(a) print a << '\n';

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<long long, long long> llll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long, long long>> vllll;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef pair<char, char> cc;
typedef pair<pair<char, char>, char> ccc;
typedef vector<char> vc;
typedef pair<int, char> ic;
typedef pair<ii, char> iic;

const int INF = 2147483647;
const ll LONGINF = 2147483647 * 1e7;

vector<int> aa;

void solve()
{
    int n, s;
    read n >> s;
    int maxim = 0;
    ll t = 0, ind = -1, savedT = -1, maxInd = -1;
    fori(n)
    {
        int a;
        read a;
        if (a > maxim && t <= s)
        {
            maxim = a;
            maxInd = i;
        }
        t += a;
        if (t <= s)
        {
            ind = i + 1;
            savedT = t;
        }
        aa.pub(a);
    }
    if (ind == aa.size()) ans(0)
    else
    {
        int res = ind;
        savedT -= maxim;
        while (savedT <= s && ind < aa.size())
        {
            savedT += aa[ind];
            ++ind;
        }
        if (res > ind - 1) ans(aa.size())
        else ans(maxInd + 1)
    }
    aa = vector<int>();
}

int main()
{
    fast
    bool mult = true;
    if (mult)
    {
        int t;
        read t;
        while (t--) solve();
    }
    else solve();
}


//
//  main.cpp
//  CF
//
//  Created by Tim Reizin on 12/27/19.
//  Copyright © 2019 Tim Reizin. All rights reserved.
//

#include <iostream>

using namespace std;

int a[100005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i)
    {
        int n, s, sum = 0;
        cin >> n >> s;
        for (int j = 0; j < n; ++j)
        {
            cin >> a[j];
            sum += a[j];
        }
        if (sum <= s) cout << "0\n";
        else
        {
        int max = 0, prop = 0;
        for (int j = 0; j < n; ++j)
        {
            int countPod = 0, sum = 0;
            for (int k = 0; k < n; ++k)
            {
                if (k != j)
                {
                    if (sum + a[k] <= s)
                    {
                        ++countPod;
                        sum += a[k];
                    }
                    else break;
                }
                if (sum == s) break;
            }
            if (countPod > max)
            {
                max = countPod;
                prop = j;
            }
        }
        cout << prop + 1 << '\n';
        }
    }
    return 0;
}


//
//  main.cpp
//  CF
//
//  Created by Tim Reizin on 12/27/19.
//  Copyright © 2019 Tim Reizin. All rights reserved.
//

#include <iostream>

using namespace std;

int a[100005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i)
    {
        int n, s, sum = 0;
        cin >> n >> s;
        for (int j = 0; j < n; ++j)
        {
            cin >> a[j];
            sum += a[j];
        }
        if (sum <= a[i]) cout << "0\n";
        else
        {
        int max = 0, prop = 0;
        for (int j = 0; j < n; ++j)
        {
            int countPod = 0, sum = 0;
            for (int k = 0; k < n; ++k)
            {
                if (k != j)
                {
                    if (sum + a[k] <= s)
                    {
                        ++countPod;
                        sum += a[k];
                    }
                    else break;
                }
                if (sum == s) break;
            }
            if (countPod > max)
            {
                max = countPod;
                prop = j;
            }
        }
        cout << prop + 1 << '\n';
        }
    }
    return 0;
}


//
//  main.cpp
//  CF
//
//  Created by Tim Reizin on 12/27/19.
//  Copyright © 2019 Tim Reizin. All rights reserved.
//

#include <iostream>

using namespace std;

int a[100005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i)
    {
        int n, s;
        cin >> n >> s;
        for (int j = 0; j < n; ++j) cin >> a[j];
        int max = 0, prop = 0;
        for (int j = 0; j < n; ++j)
        {
            int countPod = 0, sum = 0;
            for (int k = 0; k < n; ++k)
            {
                if (k != j)
                {
                    if (sum + a[k] <= s)
                    {
                        ++countPod;
                        sum += a[k];
                    }
                    else break;
                }
                if (sum == s) break;
            }
            if (countPod > max)
            {
                max = countPod;
                prop = j + 1;
            }
        }
        cout << prop << '\n';
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <sstream>

using namespace std;

#define fori(t) for(int i = 0; i < t; ++i)
#define forj(n) for(int j = 0; j < n; ++j)
#define fork(n) for(int k = 0; k < n; ++k)
#define forai(a) for(auto i : a)
#define foraj(a) for(auto j : a)
#define forak(a) for(auto k : a)
#define forp(s, n, d) for(int p = s; p < n; p += d)
#define read cin >>
#define print cout <<
#define fast cin.tie(0); cout.tie(0); std::ios_base::sync_with_stdio(0);
#define pub(a) push_back(a);
#define pob(a) pop_back(a);
#define sorti(a) sort(a.begin(), a.end());
#define sortm(a, n) sort(a, a + n);
#define fi first
#define se second
#define yes print "YES\n";
#define no print "NO\n";
#define ans(a) print a << '\n';

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<long long, long long> llll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long, long long>> vllll;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef pair<char, char> cc;
typedef pair<pair<char, char>, char> ccc;
typedef vector<char> vc;
typedef pair<int, char> ic;
typedef pair<ii, char> iic;

const int INF = 2147483647;
const ll LONGINF = 2147483647 * 1e7;

vector<int> aa;

void solve()
{
    int n, s;
    read n >> s;
    int maxim = 0;
    ll t = 0, ind = -1, savedT = -1, maxInd = -1;
    fori(n)
    {
        int a;
        read a;
        t += a;
        if (a > maxim && t <= s)
        {
            maxim = a;
            maxInd = i;
        }
        if (t <= s)
        {
            ind = i + 1;
            savedT = t;
        }
        aa.pub(a);
    }
    if (ind == aa.size()) ans(0)
    else
    {
        int res = ind;
        savedT -= maxim;
        while (savedT <= s)
        {
            savedT += aa[ind];
            ++ind;
        }
        if (res > ind - 1) ans(aa.size())
        else ans(maxInd + 1)
    }
    aa = vector<int>();
}

int main()
{
    fast
    bool mult = true;
    if (mult)
    {
        int t;
        read t;
        while (t--) solve();
    }
    else solve();
}


//
//  main.cpp
//  CF
//
//  Created by Tim Reizin on 12/27/19.
//  Copyright © 2019 Tim Reizin. All rights reserved.
//

#include <iostream>

using namespace std;

int a[100005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i)
    {
        int n, s, sum = 0;
        cin >> n >> s;
        for (int j = 0; j < n; ++j)
        {
            cin >> a[j];
            sum += a[i];
        }
        if (sum <= a[i]) cout << "0\n";
        else
        {
        int max = 0, prop = 0;
        for (int j = 0; j < n; ++j)
        {
            int countPod = 0, sum = 0;
            for (int k = 0; k < n; ++k)
            {
                if (k != j)
                {
                    if (sum + a[k] <= s)
                    {
                        ++countPod;
                        sum += a[k];
                    }
                    else break;
                }
                if (sum == s) break;
            }
            if (countPod > max)
            {
                max = countPod;
                prop = j + 1;
            }
        }
        cout << prop << '\n';
        }
    }
    return 0;
}


#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <sstream>

using namespace std;

#define fori(t) for(int i = 0; i < t; ++i)
#define forj(n) for(int j = 0; j < n; ++j)
#define fork(n) for(int k = 0; k < n; ++k)
#define forai(a) for(auto i : a)
#define foraj(a) for(auto j : a)
#define forak(a) for(auto k : a)
#define forp(s, n, d) for(int p = s; p < n; p += d)
#define read cin >>
#define print cout <<
#define fast cin.tie(0); cout.tie(0); std::ios_base::sync_with_stdio(0);
#define pub(a) push_back(a);
#define pob(a) pop_back(a);
#define sorti(a) sort(a.begin(), a.end());
#define sortm(a, n) sort(a, a + n);
#define fi first
#define se second
#define yes print "YES\n";
#define no print "NO\n";
#define ans(a) print a << '\n';

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef pair<long long, long long> llll;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long, long long>> vllll;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef pair<char, char> cc;
typedef pair<pair<char, char>, char> ccc;
typedef vector<char> vc;
typedef pair<int, char> ic;
typedef pair<ii, char> iic;

const int INF = 2147483647;
const ll LONGINF = 2147483647 * 1e7;

vector<int> aa;

void solve()
{
    int n, s;
    read n >> s;
    int maxim = 0;
    ll t = 0, ind = -1, savedT = -1, maxInd = -1;
    fori(n)
    {
        int a;
        read a;
        t += a;
        if (a > maxim && t <= s)
        {
            maxim = a;
            maxInd = i;
        }
        if (t <= s)
        {
            ind = i + 1;
            savedT = t;
        }
        aa.pub(a);
    }
    if (ind == aa.size()) ans(0)
    else
    {
        int res = ind;
        savedT -= maxim;
        while (savedT <= s && ind < aa.size())
        {
            savedT += aa[ind];
            ++ind;
        }
        if (res > ind - 1) ans(aa.size())
        else ans(maxInd + 1)
    }
    aa = vector<int>();
}

int main()
{
    fast
    bool mult = true;
    if (mult)
    {
        int t;
        read t;
        while (t--) solve();
    }
    else solve();
}


//
//  main.cpp
//  CF
//
//  Created by Tim Reizin on 12/27/19.
//  Copyright © 2019 Tim Reizin. All rights reserved.
//

#include <iostream>

using namespace std;

int a[100005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i)
    {
        int n, s, sum = 0, maxim = -1, maximIndex = 0, countPodStart = 0;
        cin >> n >> s;
        for (int j = 0; j < n; ++j)
        {
            cin >> a[j];
            if (a[j] > maxim && sum <= s)
            {
                maxim = a[j];
                maximIndex = j;
            }
            if (sum + a[j] <= s)
            {
                ++countPodStart;
            }
            sum += a[j];
        }
        if (sum <= s || maxim == 0) cout << "0\n";
        else
        {
            int countPod = 0, sum = 0;
            for (int k = 0; k < n; ++k)
            {
                if (k != maximIndex)
                {
                    if (sum + a[k] <= s)
                    {
                        ++countPod;
                        sum += a[k];
                    }
                    else break;
                }
                if (sum == s) break;
            }
            if (countPod > countPodStart)
            {
                cout << maximIndex + 1 << '\n';
            }
            else cout << 0 << '\n';
        }
    }
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<math.h>
#include<stdlib.h>
#include<unordered_map>
#define ll  long long
#define pb push_back
#define PI (acos(-1))
#define INF 0x3f3f3f3f
using namespace std;
inline int re()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
int a[100100];
int sum[100100];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++) {
            a[i]=re();
            sum[i]=sum[i-1]+a[i];
        }
        int maxx=0;
        int maxi=0;
        if(sum[n]<=m) {
            cout<<0<<endl;continue;
        }
        int jia;
        for(int i=1;i<=n;i++)
        {
            if(m<sum[i-1]) break;
            jia=m-sum[i-1];
            jia+=sum[i];
            int pos=upper_bound(sum+i+1,sum+1+n,jia)-sum;
            if(pos-2>maxx)
            {
                maxx=pos-2;
                maxi=i;
            }
        }
        cout<<maxi<<endl;
    }
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<math.h>
#include<stdlib.h>
#include<unordered_map>
#define ll  long long
#define pb push_back
#define PI (acos(-1))
#define INF 0x3f3f3f3f
using namespace std;
inline int re()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
ll a[100100];
ll sum[100100];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++) {
            a[i]=re();
            sum[i]=sum[i-1]+a[i];
        }
        ll maxx=0,maxi=0;
        for(int i=1;i<=n;i++)
        {
            if(m<a[i-1]) break;
            ll p=m+a[i];
            int pos=upper_bound(sum+1,sum+1+n,p)-sum;
            if(pos-2>maxx){
                maxx=pos-2;
                maxi=i;
            }
        }
        cout<<maxi<<endl;

    }
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<math.h>
#include<stdlib.h>
#include<unordered_map>
#define ll  long long
#define pb push_back
#define PI (acos(-1))
#define INF 0x3f3f3f3f
using namespace std;
inline int re()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
ll a[100100];
ll sum[100100];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++) {
            a[i]=re();
            sum[i]=sum[i-1]+a[i];
        }
        int maxx=0;
        int maxi=0;
        if(sum[n]<=m) {
            cout<<0<<endl;continue;
        }
        ll jia;
        for(int i=1;i<=n;i++)
        {
            if(m<sum[i-1]) break;
            jia=m-sum[i-1];
            jia+=sum[i];
            int pos=upper_bound(sum+i+1,sum+1+n,jia)-sum;
            if(pos-2>maxx)
            {
                maxx=pos-2;
                maxi=i;
            }
        }
        cout<<maxi<<endl;
    }
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<math.h>
#include<stdlib.h>
#include<unordered_map>
#define ll  long long
#define pb push_back
#define PI (acos(-1))
#define INF 0x3f3f3f3f
using namespace std;
inline int re()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
ll a[100100];
ll sum[100100];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        ll maxx=0,maxi=0;
        for(int i=1;i<=n;i++) {
            a[i]=re();
            sum[i]=sum[i-1]+a[i];
            if(sum[i]<=m) maxx=i;
        }
        if(m>=sum[n]) {
            cout<<0<<endl;
            continue;
        }
        for(int i=1;i<=n;i++)
        {
            if(m<sum[i-1]) break;
            ll p=m+a[i];
            int pos=upper_bound(sum+1,sum+1+n,p)-sum;
            if(pos-2>maxx){
                maxx=pos-2;
                maxi=i;
            }
        }
        cout<<maxi<<endl;

    }
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<math.h>
#include<stdlib.h>
#include<unordered_map>
#define ll  long long
#define pb push_back
#define PI (acos(-1))
#define INF 0x3f3f3f3f
using namespace std;
inline int re()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
ll a[100100];
ll sum[100100];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        ll maxx=0,maxi=0;
        for(int i=1;i<=n;i++) {
            a[i]=re();
            sum[i]=sum[i-1]+a[i];
            if(sum[i]<=m) maxx=i;
        }
        if(m>=sum[n]) {
            cout<<0<<endl;
            continue;
        }
        for(int i=1;i<=n;i++)
        {
            if(m<a[i-1]) break;
            ll p=m+a[i];
            int pos=upper_bound(sum+1,sum+1+n,p)-sum;
            if(pos-2>maxx){
                maxx=pos-2;
                maxi=i;
            }
        }
        cout<<maxi<<endl;

    }
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<math.h>
#include<stdlib.h>
#include<unordered_map>
#define ll  long long
#define pb push_back
#define PI (acos(-1))
#define INF 0x3f3f3f3f
using namespace std;
inline int re()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
int a[100100];
int sum[100100];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++) {
            a[i]=re();
            sum[i]=sum[i-1]+a[i];
        }
        int maxx=0;
        int maxi=0;
        if(sum[n]<=m) {
            cout<<0<<endl;continue;
        }
        int jia;
        for(int i=1;i<=n;i++)
        {
            if(m<=sum[i-1]) break;
            jia=m-sum[i-1];
            jia+=sum[i];
            int pos=upper_bound(sum+i+1,sum+1+n,jia)-sum;
            if(pos-2>maxx)
            {
                maxx=pos-2;
                maxi=i;
            }
        }
        cout<<maxi<<endl;
    }
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<math.h>
#include<stdlib.h>
#include<unordered_map>
#define ll  long long
#define pb push_back
#define PI (acos(-1))
#define INF 0x3f3f3f3f
using namespace std;
inline int re()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
ll a[100100];
ll sum[100100];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++) {
            a[i]=re();
            sum[i]=sum[i-1]+a[i];
        }
        ll maxx=0,maxi=0;
        for(int i=1;i<=n;i++)
        {
            if(m<=a[i-1]) break;
            ll p=m+a[i];
            int pos=upper_bound(sum+1,sum+1+n,p)-sum;
            if(pos-2>maxx){
                maxx=pos-2;
                maxi=i;
            }
        }
        cout<<maxi<<endl;

    }
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<math.h>
#include<stdlib.h>
#include<unordered_map>
#define ll  long long
#define pb push_back
#define PI (acos(-1))
#define INF 0x3f3f3f3f
using namespace std;
inline int re()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
int a[100100];
int sum[100100];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++) {
            a[i]=re();
            sum[i]=sum[i-1]+a[i];
        }
        int maxx=0;
        int maxi=0;
        if(sum[n]<=m) {
            cout<<0<<endl;continue;
        }
        int jia;
        for(int i=1;i<=n;i++)
        {
            if(m<=sum[i-1]) continue;
            jia=m+sum[i];
            int pos=upper_bound(sum+i+1,sum+1+n,jia)-sum;
            if(pos-2>maxx)
            {
                maxx=pos-2;
                maxi=i;
            }
        }
        cout<<maxi<<endl;
    }
}


#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<queue>
#include<set>
#include<math.h>
#include<stdlib.h>
#include<unordered_map>
#define ll  long long
#define pb push_back
#define PI (acos(-1))
#define INF 0x3f3f3f3f
using namespace std;
inline int re()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){ x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return x*f;
}
int a[100100];
int sum[100100];
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,m;
        cin>>n>>m;
        for(int i=1;i<=n;i++) {
            a[i]=re();
            sum[i]=sum[i-1]+a[i];
        }
        int maxx=0,maxi=0;
        for(int i=1;i<=n;i++)
        {
            if(m<=a[i-1]) break;
            int p=m+a[i];
            int pos=upper_bound(sum+1,sum+1+n,p)-sum;
            if(pos-2>maxx){
                maxx=pos-2;
                maxi=i;
            }
        }
        cout<<maxi<<endl;

    }
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,n)    for(int i = 0; x < n; i++)
#define fr(i,j,n)   for(ll i=j;i<n;i++)
#define tc           ll t1; cin>>t1; while(t1--)
#define inp          ll n; cin>>n; ll a[n]; fr(i,0,n) cin>>a[i];
#define inp1         ll n1; cin>>n1; ll a[n1]; fr(i,0,n1) cin>>a[i];
#define vec          vector<ll>
#define pb           push_back
#define pii          pair<ll,ll>
#define mp           make_pair
#define F            first
#define S            second
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define scn(n)       scanf("%lld",&n)
#define lscn(n)      scanf("%lld",&n)
#define lpri(n)      printf("%lld",n)
#define pri(n)       printf("%d",n)
#define pln()        printf("\n")
#define priln(n)     printf("%d\n",n)
#define lpriln(n)    printf("%lld\n",n)
#define srt(v)       sort(v.begin(),v.end())
#define srte(v)      sort(v.rbegin(),v.rend())
#define maxx         1000005
#define lb(v,n)        lower_bound(v.begin(),v.end(),n)-v.begin()
#define ub(v,n)        upper_bound(v.begin(),v.end(),n)-v.begin()
//#define v(n,m)       v.assign(n,m);     //use this
#define inf          LONG_MAX
#define zer          LONG_MIN
const long mod=pow(10,9)+7;

struct st {
  int a,b,c;
};

comp(st aa,st bb){
  if(aa.a==bb.a) return aa.c<bb.c;
  return aa.a<bb.a;
}

int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("in2.txt" , "r" , stdin);
    freopen("op2.txt" , "w" , stdout);
    #endif

    tc{
      ll n,k;
      cin>>n>>k;
      vector<ll> a(n),b(n);
      fr(i,0,n) {cin>>a[i]; b[i]=a[i];}
      fr(i,1,n) a[i]=a[i-1]+a[i];
      // fr(i,0,n) cout<<a[i]<<" ";
      ll ans=INT_MIN,res=0;
      if(a[n-1]<=k) ans=n;
      fr(i,1,n){
        ll temp=b[i-1] + k;

        ll ind=ub(a,temp);

        ind--;
        // cout<<temp<<" "<<ind<<" "<<endl;
        if(ans<ind) {
          res=i;
          ans=max(ans,ind);
        }
      }

      cout<<res<<endl;
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,n)    for(int i = 0; x < n; i++)
#define fr(i,j,n)   for(ll i=j;i<n;i++)
#define tc           ll t1; cin>>t1; while(t1--)
#define inp          ll n; cin>>n; ll a[n]; rep(i,0,n) cin>>a[i];
#define inp1         ll n1; cin>>n1; ll a[n1]; rep(i,0,n1) cin>>a[i];
#define vec          vector<ll>
#define pb           push_back
#define pii          pair<ll,ll>
#define mp           make_pair
#define F            first
#define S            second
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define scn(n)       scanf("%lld",&n)
#define lscn(n)      scanf("%lld",&n)
#define lpri(n)      printf("%lld",n)
#define pri(n)       printf("%d",n)
#define pln()        printf("\n")
#define priln(n)     printf("%d\n",n)
#define lpriln(n)    printf("%lld\n",n)
#define srt(v)       sort(v.begin(),v.end())
#define srte(v)      sort(v.rbegin(),v.rend())
#define maxx         1000005
//#define v(n,m)       v.assign(n,m);     //use this
#define inf          LONG_MAX
#define zer          LONG_MIN
const long mod=pow(10,9)+7;
bool comp(const pair<int,int> &a, const pair<int,int> &b)
   {
    if(a.second==b.second) return a.first < b.first;
      return (a.second < b.second);
   }
int  main(){

     #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
    #endif

   tc{

   	 ll n,t;
   	 cin>>n>>t;
   	 vector<ll> a(n);

   	 fr(i,0,n) cin>>a[i];

     ll temp=0,m=a[0],mi=1,f=0,c=0;

   	 fr(i,0,n){

        temp+=a[i];

        if(temp<=t){
        	if(m<a[i]) {m=a[i]; mi=i+1;}
        }
        else if(i != n-1){
        	if(a[i+1]>=m) mi=0;
            else break;
        }
       // cout<<mi<<" ";

   	 }

   	 if(n==1) mi=0;

   	 cout<<mi<<endl;

   }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,n)    for(int i = 0; x < n; i++)
#define fr(i,j,n)   for(ll i=j;i<n;i++)
#define tc           ll t1; cin>>t1; while(t1--)
#define inp          ll n; cin>>n; ll a[n]; rep(i,0,n) cin>>a[i];
#define inp1         ll n1; cin>>n1; ll a[n1]; rep(i,0,n1) cin>>a[i];
#define vec          vector<ll>
#define pb           push_back
#define pii          pair<ll,ll>
#define mp           make_pair
#define F            first
#define S            second
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define scn(n)       scanf("%lld",&n)
#define lscn(n)      scanf("%lld",&n)
#define lpri(n)      printf("%lld",n)
#define pri(n)       printf("%d",n)
#define pln()        printf("\n")
#define priln(n)     printf("%d\n",n)
#define lpriln(n)    printf("%lld\n",n)
#define srt(v)       sort(v.begin(),v.end())
#define srte(v)      sort(v.rbegin(),v.rend())
#define maxx         1000005
//#define v(n,m)       v.assign(n,m);     //use this
#define inf          LONG_MAX
#define zer          LONG_MIN
const long mod=pow(10,9)+7;
bool comp(const pair<int,int> &a, const pair<int,int> &b)
   {
    if(a.second==b.second) return a.first < b.first;
      return (a.second < b.second);
   }
int  main(){

     #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
    #endif

   tc{

   	 ll n,t;
   	 cin>>n>>t;
   	 vector<ll> a(n);

   	 fr(i,0,n) cin>>a[i];

   	 std::vector<ll> v;
   	 std::vector<ll> v2;
   	 std::map<ll, ll> m,m2;

   	 fr(i,0,n) v.pb(a[i]);
   	 srt(v);
      ll temp =0,c=0;
   	 fr(i,0,n)
   	 {temp+=v[i]; if(temp<=t) { v2.pb(v[i]); m[v[i]]++; m2[v[i]]++; }   else break;}

   //   	 cout<<m[1]<<" ";
 	 // cout<<v2.size()<<" ";

     fr(i,0,n){

       if(m2[a[i]])
        if(m[a[i]]>0){
        	m[a[i]]--; if(m[a[i]]==0) m.erase(a[i]); if(m.size()==0) break;
        	// cout<<endl<<m[1]<<" ";
        	// cout<<m.size()<<" ";
        }
        c=i+1;
     }
     // cout<<c;

     if(c!=n) c++;

     cout<<c-v2.size()<<endl;

   }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,n)    for(int i = 0; x < n; i++)
#define fr(i,j,n)   for(ll i=j;i<n;i++)
#define tc           ll t1; cin>>t1; while(t1--)
#define inp          ll n; cin>>n; ll a[n]; rep(i,0,n) cin>>a[i];
#define inp1         ll n1; cin>>n1; ll a[n1]; rep(i,0,n1) cin>>a[i];
#define vec          vector<ll>
#define pb           push_back
#define pii          pair<ll,ll>
#define mp           make_pair
#define F            first
#define S            second
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define scn(n)       scanf("%lld",&n)
#define lscn(n)      scanf("%lld",&n)
#define lpri(n)      printf("%lld",n)
#define pri(n)       printf("%d",n)
#define pln()        printf("\n")
#define priln(n)     printf("%d\n",n)
#define lpriln(n)    printf("%lld\n",n)
#define srt(v)       sort(v.begin(),v.end())
#define srte(v)      sort(v.rbegin(),v.rend())
#define maxx         1000005
//#define v(n,m)       v.assign(n,m);     //use this
#define inf          LONG_MAX
#define zer          LONG_MIN
const long mod=pow(10,9)+7;
bool comp(const pair<int,int> &a, const pair<int,int> &b)
   {
    if(a.second==b.second) return a.first < b.first;
      return (a.second < b.second);
   }
int  main(){

     #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
    #endif

   tc{

   	 ll n,t;
   	 cin>>n>>t;
   	 vector<ll> a(n);

   	 fr(i,0,n) cin>>a[i];

     ll temp=0,m=a[0],mi=1,f=0,c=0;

   	 fr(i,0,n){

        temp+=a[i];

        if(temp<=t){
        	if(m<a[i]) {m=a[i]; mi=i+1;}
        }
        else if(i!=n-1){
        	if(a[i]>=m) mi=0;
            else break;
        }

   	 }

   	 cout<<mi<<endl;

   }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,n)    for(int i = 0; x < n; i++)
#define fr(i,j,n)   for(ll i=j;i<n;i++)
#define tc           ll t1; cin>>t1; while(t1--)
#define inp          ll n; cin>>n; ll a[n]; rep(i,0,n) cin>>a[i];
#define inp1         ll n1; cin>>n1; ll a[n1]; rep(i,0,n1) cin>>a[i];
#define vec          vector<ll>
#define pb           push_back
#define pii          pair<ll,ll>
#define mp           make_pair
#define F            first
#define S            second
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define scn(n)       scanf("%lld",&n)
#define lscn(n)      scanf("%lld",&n)
#define lpri(n)      printf("%lld",n)
#define pri(n)       printf("%d",n)
#define pln()        printf("\n")
#define priln(n)     printf("%d\n",n)
#define lpriln(n)    printf("%lld\n",n)
#define srt(v)       sort(v.begin(),v.end())
#define srte(v)      sort(v.rbegin(),v.rend())
#define maxx         1000005
//#define v(n,m)       v.assign(n,m);     //use this
#define inf          LONG_MAX
#define zer          LONG_MIN
const long mod=pow(10,9)+7;
bool comp(const pair<int,int> &a, const pair<int,int> &b)
   {
    if(a.second==b.second) return a.first < b.first;
      return (a.second < b.second);
   }
int  main(){

     #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
    #endif

   tc{

   	 ll n,t;
   	 cin>>n>>t;
   	 vector<ll> a(n);

   	 fr(i,0,n) cin>>a[i];

   	 std::vector<ll> v;
   	 std::vector<ll> v2;
   	 std::map<ll, ll> m,m2;

   	 fr(i,0,n) v.pb(a[i]);
   	 srt(v);
      ll temp =0,c=0;
   	 fr(i,0,n)
   	 {temp+=v[i]; if(temp<=t) { v2.pb(v[i]); m[v[i]]++; m2[v[i]]++; }   else break;}

   //   	 cout<<m[1]<<" ";
 	 // cout<<v2.size()<<" ";

     fr(i,0,n){

       if(m2[a[i]]>0)
        {
        	m2[a[i]]--;
        	m[a[i]]--; if(m[a[i]]==0) m.erase(a[i]); if(m.size()==0) break;
        	// cout<<endl<<m[1]<<" ";
        	// cout<<m.size()<<" ";
        }
        c=i+1;
     }
     // cout<<c;

     if(c!=n) c++;

     cout<<c-v2.size()<<endl;

   }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,n)    for(int i = 0; x < n; i++)
#define fr(i,j,n)   for(ll i=j;i<n;i++)
#define tc           ll t1; cin>>t1; while(t1--)
#define inp          ll n; cin>>n; ll a[n]; rep(i,0,n) cin>>a[i];
#define inp1         ll n1; cin>>n1; ll a[n1]; rep(i,0,n1) cin>>a[i];
#define vec          vector<ll>
#define pb           push_back
#define pii          pair<ll,ll>
#define mp           make_pair
#define F            first
#define S            second
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define scn(n)       scanf("%lld",&n)
#define lscn(n)      scanf("%lld",&n)
#define lpri(n)      printf("%lld",n)
#define pri(n)       printf("%d",n)
#define pln()        printf("\n")
#define priln(n)     printf("%d\n",n)
#define lpriln(n)    printf("%lld\n",n)
#define srt(v)       sort(v.begin(),v.end())
#define srte(v)      sort(v.rbegin(),v.rend())
#define maxx         1000005
//#define v(n,m)       v.assign(n,m);     //use this
#define inf          LONG_MAX
#define zer          LONG_MIN
const long mod=pow(10,9)+7;
bool comp(const pair<int,int> &a, const pair<int,int> &b)
   {
    if(a.second==b.second) return a.first < b.first;
      return (a.second < b.second);
   }
int  main(){

     #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
    #endif

   tc{

   	 ll n,t;
   	 cin>>n>>t;
   	 vector<ll> a(n);

   	 fr(i,0,n) cin>>a[i];

     ll temp=0,m=a[0],mi=1,f=0,c=0;

   	 fr(i,0,n){

        temp+=a[i];
        if(temp<=t){
        	if(a[i]>m && f==0){
               m=a[i]; mi=i+1;
        	}
        }
        else if(f==0){
        	temp-=m; f++;
        }
        else break;
        //cout<<temp<<" ";
        c=i+1;
   	 }

   	 if(c==n && f==0 ) mi=0;

   	 cout<<mi<<endl;

   }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,n)    for(int i = 0; x < n; i++)
#define fr(i,j,n)   for(ll i=j;i<n;i++)
#define tc           ll t1; cin>>t1; while(t1--)
#define inp          ll n; cin>>n; ll a[n]; fr(i,0,n) cin>>a[i];
#define inp1         ll n1; cin>>n1; ll a[n1]; fr(i,0,n1) cin>>a[i];
#define vec          vector<ll>
#define pb           push_back
#define pii          pair<ll,ll>
#define mp           make_pair
#define F            first
#define S            second
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define scn(n)       scanf("%lld",&n)
#define lscn(n)      scanf("%lld",&n)
#define lpri(n)      printf("%lld",n)
#define pri(n)       printf("%d",n)
#define pln()        printf("\n")
#define priln(n)     printf("%d\n",n)
#define lpriln(n)    printf("%lld\n",n)
#define srt(v)       sort(v.begin(),v.end())
#define srte(v)      sort(v.rbegin(),v.rend())
#define maxx         1000005
#define lb(v,n)        lower_bound(v.begin(),v.end(),n)-v.begin()
#define ub(v,n)        upper_bound(v.begin(),v.end(),n)-v.begin()
//#define v(n,m)       v.assign(n,m);     //use this
#define inf          LONG_MAX
#define zer          LONG_MIN
const long mod=pow(10,9)+7;

struct st {
  int a,b,c;
};

comp(st aa,st bb){
  if(aa.a==bb.a) return aa.c<bb.c;
  return aa.a<bb.a;
}

int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("in2.txt" , "r" , stdin);
    freopen("op2.txt" , "w" , stdout);
    #endif

    tc{
      ll n,k;
      cin>>n>>k;
      vector<ll> a(n),b(n);
      fr(i,0,n) {cin>>a[i]; b[i]=a[i];}
      fr(i,1,n) a[i]=a[i-1]+a[i];
      // fr(i,0,n) cout<<a[i]<<" ";
      ll ans=INT_MIN,res=0,ind=-1;
      if(a[n-1]<=k) ans=n;
      if(a[n-2]<=k) ans=n-1;
      // cout<<ans<<" ";
      ll temp=0,flag=0;
      if(!(ans>=0)){
         fr(i,0,n){

        temp+=b[i];
        if(b[i]>ans && flag==0){
          ans=b[i]; ind=i+1;
        }
        if(temp>=k && flag) break;
        if(temp>k && flag==0){
          temp-=ans; flag=1;
        }

      }
      }else{
        ind=0;
      }

      cout<<ind<<endl;
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,n)    for(int i = 0; x < n; i++)
#define fr(i,j,n)   for(ll i=j;i<n;i++)
#define tc           ll t1; cin>>t1; while(t1--)
#define inp          ll n; cin>>n; ll a[n]; rep(i,0,n) cin>>a[i];
#define inp1         ll n1; cin>>n1; ll a[n1]; rep(i,0,n1) cin>>a[i];
#define vec          vector<ll>
#define pb           push_back
#define pii          pair<ll,ll>
#define mp           make_pair
#define F            first
#define S            second
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define scn(n)       scanf("%lld",&n)
#define lscn(n)      scanf("%lld",&n)
#define lpri(n)      printf("%lld",n)
#define pri(n)       printf("%d",n)
#define pln()        printf("\n")
#define priln(n)     printf("%d\n",n)
#define lpriln(n)    printf("%lld\n",n)
#define srt(v)       sort(v.begin(),v.end())
#define srte(v)      sort(v.rbegin(),v.rend())
#define maxx         1000005
//#define v(n,m)       v.assign(n,m);     //use this
#define inf          LONG_MAX
#define zer          LONG_MIN
const long mod=pow(10,9)+7;
bool comp(const pair<int,int> &a, const pair<int,int> &b)
   {
    if(a.second==b.second) return a.first < b.first;
      return (a.second < b.second);
   }
int  main(){

     #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
    #endif

   tc{

   	 ll n,t;
   	 cin>>n>>t;
   	 vector<ll> a(n);
    ll sum=0;

   	 fr(i,0,n) {cin>>a[i]; sum+=a[i];}

     ll temp=0,m=a[0],mi=1,f=0,c=0;
     int i=0;
   	 for(i=0;i<n;i++){

        temp+=a[i];

        if(temp<=t){
        	if(m<a[i]) {m=a[i]; mi=i+1;}
       }
       else break;
   	 }

   	 if( i<n && a[i]<=m) ;
   	 else mi=0;

   	 cout<<mi<<endl;

   }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,n)    for(int i = 0; x < n; i++)
#define fr(i,j,n)   for(ll i=j;i<n;i++)
#define tc           ll t1; cin>>t1; while(t1--)
#define inp          ll n; cin>>n; ll a[n]; rep(i,0,n) cin>>a[i];
#define inp1         ll n1; cin>>n1; ll a[n1]; rep(i,0,n1) cin>>a[i];
#define vec          vector<ll>
#define pb           push_back
#define pii          pair<ll,ll>
#define mp           make_pair
#define F            first
#define S            second
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define scn(n)       scanf("%lld",&n)
#define lscn(n)      scanf("%lld",&n)
#define lpri(n)      printf("%lld",n)
#define pri(n)       printf("%d",n)
#define pln()        printf("\n")
#define priln(n)     printf("%d\n",n)
#define lpriln(n)    printf("%lld\n",n)
#define srt(v)       sort(v.begin(),v.end())
#define srte(v)      sort(v.rbegin(),v.rend())
#define maxx         1000005
//#define v(n,m)       v.assign(n,m);     //use this
#define inf          LONG_MAX
#define zer          LONG_MIN
const long mod=pow(10,9)+7;
bool comp(const pair<int,int> &a, const pair<int,int> &b)
   {
    if(a.second==b.second) return a.first < b.first;
      return (a.second < b.second);
   }
int  main(){

     #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
    #endif

   tc{

   	 ll n,t;
   	 cin>>n>>t;
   	 vector<ll> a(n);
    ll sum=0;

   	 fr(i,0,n) {cin>>a[i]; sum+=a[i];}

     ll temp=0,m=a[0],mi=1,f=0,c=0;
     int i=0;
   	 for(i=0;i<n;i++){

        temp+=a[i];

        if(temp<=t){
        	if(m<a[i]) {m=a[i]; mi=i+1;}
       }
       else break;
   	 }

   	 if( i<n-1 && a[i+1]<m) ;
   	 else mi=0;

   	 cout<<mi<<endl;

   }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,n)    for(int i = 0; x < n; i++)
#define fr(i,j,n)   for(ll i=j;i<n;i++)
#define tc           ll t1; cin>>t1; while(t1--)
#define inp          ll n; cin>>n; ll a[n]; rep(i,0,n) cin>>a[i];
#define inp1         ll n1; cin>>n1; ll a[n1]; rep(i,0,n1) cin>>a[i];
#define vec          vector<ll>
#define pb           push_back
#define pii          pair<ll,ll>
#define mp           make_pair
#define F            first
#define S            second
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define scn(n)       scanf("%lld",&n)
#define lscn(n)      scanf("%lld",&n)
#define lpri(n)      printf("%lld",n)
#define pri(n)       printf("%d",n)
#define pln()        printf("\n")
#define priln(n)     printf("%d\n",n)
#define lpriln(n)    printf("%lld\n",n)
#define srt(v)       sort(v.begin(),v.end())
#define srte(v)      sort(v.rbegin(),v.rend())
#define maxx         1000005
//#define v(n,m)       v.assign(n,m);     //use this
#define inf          LONG_MAX
#define zer          LONG_MIN
const long mod=pow(10,9)+7;
bool comp(const pair<int,int> &a, const pair<int,int> &b)
   {
    if(a.second==b.second) return a.first < b.first;
      return (a.second < b.second);
   }
int  main(){

     #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
    #endif

   tc{

   	 ll n,t;
   	 cin>>n>>t;
   	 vector<ll> a(n);

   	 fr(i,0,n) cin>>a[i];

     ll temp=0,m=a[0],mi=0,f=0,c=0;

   	 fr(i,0,n){

        temp+=a[i];

        if(temp<=t){
        	if(m<a[i]) {m=a[i]; mi=i+1;}
        }
        else if(i!=n-1){
        	if(a[i]>=m) mi=0;
            else break;
        }

   	 }

   	 cout<<mi<<endl;

   }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,n)    for(int i = 0; x < n; i++)
#define fr(i,j,n)   for(ll i=j;i<n;i++)
#define tc           ll t1; cin>>t1; while(t1--)
#define inp          ll n; cin>>n; ll a[n]; fr(i,0,n) cin>>a[i];
#define inp1         ll n1; cin>>n1; ll a[n1]; fr(i,0,n1) cin>>a[i];
#define vec          vector<ll>
#define pb           push_back
#define pii          pair<ll,ll>
#define mp           make_pair
#define F            first
#define S            second
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define scn(n)       scanf("%lld",&n)
#define lscn(n)      scanf("%lld",&n)
#define lpri(n)      printf("%lld",n)
#define pri(n)       printf("%d",n)
#define pln()        printf("\n")
#define priln(n)     printf("%d\n",n)
#define lpriln(n)    printf("%lld\n",n)
#define srt(v)       sort(v.begin(),v.end())
#define srte(v)      sort(v.rbegin(),v.rend())
#define maxx         1000005
#define lb(v,n)        lower_bound(v.begin(),v.end(),n)-v.begin()
#define ub(v,n)        upper_bound(v.begin(),v.end(),n)-v.begin()
//#define v(n,m)       v.assign(n,m);     //use this
#define inf          LONG_MAX
#define zer          LONG_MIN
const long mod=pow(10,9)+7;

struct st {
  int a,b,c;
};

comp(st aa,st bb){
  if(aa.a==bb.a) return aa.c<bb.c;
  return aa.a<bb.a;
}

int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("in2.txt" , "r" , stdin);
    freopen("op2.txt" , "w" , stdout);
    #endif

    tc{
      ll n,k;
      cin>>n>>k;
      vector<ll> a(n),b(n);
      fr(i,0,n) {cin>>a[i]; b[i]=a[i];}
      fr(i,1,n) a[i]=a[i-1]+a[i];
      // fr(i,0,n) cout<<a[i]<<" ";
      ll ans=INT_MIN,res=0;
      // if(a[n-1]<=k) ans=n;
      // if(a[n-2]<=k) ans=n-1;
      fr(i,0,n){
        ll temp=b[i] + k;

        ll ind=ub(a,temp);

        ind--;
        // cout<<temp<<" "<<ind<<" "<<endl;
        if(ans<ind) {
          res=i+1;
          ans=ind;
        }
      }

      cout<<res<<endl;
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,n)    for(int i = 0; x < n; i++)
#define fr(i,j,n)   for(ll i=j;i<n;i++)
#define tc           ll t1; cin>>t1; while(t1--)
#define inp          ll n; cin>>n; ll a[n]; rep(i,0,n) cin>>a[i];
#define inp1         ll n1; cin>>n1; ll a[n1]; rep(i,0,n1) cin>>a[i];
#define vec          vector<ll>
#define pb           push_back
#define pii          pair<ll,ll>
#define mp           make_pair
#define F            first
#define S            second
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define scn(n)       scanf("%lld",&n)
#define lscn(n)      scanf("%lld",&n)
#define lpri(n)      printf("%lld",n)
#define pri(n)       printf("%d",n)
#define pln()        printf("\n")
#define priln(n)     printf("%d\n",n)
#define lpriln(n)    printf("%lld\n",n)
#define srt(v)       sort(v.begin(),v.end())
#define srte(v)      sort(v.rbegin(),v.rend())
#define maxx         1000005
//#define v(n,m)       v.assign(n,m);     //use this
#define inf          LONG_MAX
#define zer          LONG_MIN
const long mod=pow(10,9)+7;
bool comp(const pair<int,int> &a, const pair<int,int> &b)
   {
    if(a.second==b.second) return a.first < b.first;
      return (a.second < b.second);
   }
int  main(){

     #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
    #endif

   tc{

   	 ll n,t;
   	 cin>>n>>t;
   	 vector<ll> a(n);
    ll sum=0;

   	 fr(i,0,n) {cin>>a[i]; sum+=a[i];}

     ll temp=0,m=a[0],mi=1,f=0,c=0;
     int i=0;
   	 for(i=0;i<n;i++){

        temp+=a[i];

        if(temp<=t){
        	if(m<a[i]) {m=a[i]; mi=i+1;}
       }
       else break;
   	 }

   	 if( i<n-1 && a[i+1]<=m) ;
   	 else mi=0;

   	 cout<<mi<<endl;

   }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,n)    for(int i = 0; x < n; i++)
#define fr(i,j,n)   for(ll i=j;i<n;i++)
#define tc           ll t1; cin>>t1; while(t1--)
#define inp          ll n; cin>>n; ll a[n]; rep(i,0,n) cin>>a[i];
#define inp1         ll n1; cin>>n1; ll a[n1]; rep(i,0,n1) cin>>a[i];
#define vec          vector<ll>
#define pb           push_back
#define pii          pair<ll,ll>
#define mp           make_pair
#define F            first
#define S            second
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define scn(n)       scanf("%lld",&n)
#define lscn(n)      scanf("%lld",&n)
#define lpri(n)      printf("%lld",n)
#define pri(n)       printf("%d",n)
#define pln()        printf("\n")
#define priln(n)     printf("%d\n",n)
#define lpriln(n)    printf("%lld\n",n)
#define srt(v)       sort(v.begin(),v.end())
#define srte(v)      sort(v.rbegin(),v.rend())
#define maxx         1000005
//#define v(n,m)       v.assign(n,m);     //use this
#define inf          LONG_MAX
#define zer          LONG_MIN
const long mod=pow(10,9)+7;
bool comp(const pair<int,int> &a, const pair<int,int> &b)
   {
    if(a.second==b.second) return a.first < b.first;
      return (a.second < b.second);
   }
int  main(){

     #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
    #endif

   tc{

   	 ll n,t;
   	 cin>>n>>t;
   	 vector<ll> a(n);
    ll sum=0;

   	 fr(i,0,n) {cin>>a[i]; sum+=a[i];}

     ll temp=0,m=a[0],mi=1,f=0,c=0;

   	 fr(i,0,n){

        temp+=a[i];

        if(temp<=t){
        	if(m<a[i]) {m=a[i]; mi=i+1;}
        }
        else if(i != n-1){
        	if(a[i+1]>=m) mi=0;
            else break;
        }
       // cout<<mi<<" ";

   	 }

   	 if(n==1) mi=0;
   	 if(sum<=t) mi=0;

   	 cout<<mi<<endl;

   }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,n)    for(int i = 0; x < n; i++)
#define fr(i,j,n)   for(ll i=j;i<n;i++)
#define tc           ll t1; cin>>t1; while(t1--)
#define inp          ll n; cin>>n; ll a[n]; fr(i,0,n) cin>>a[i];
#define inp1         ll n1; cin>>n1; ll a[n1]; fr(i,0,n1) cin>>a[i];
#define vec          vector<ll>
#define pb           push_back
#define pii          pair<ll,ll>
#define mp           make_pair
#define F            first
#define S            second
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define scn(n)       scanf("%lld",&n)
#define lscn(n)      scanf("%lld",&n)
#define lpri(n)      printf("%lld",n)
#define pri(n)       printf("%d",n)
#define pln()        printf("\n")
#define priln(n)     printf("%d\n",n)
#define lpriln(n)    printf("%lld\n",n)
#define srt(v)       sort(v.begin(),v.end())
#define srte(v)      sort(v.rbegin(),v.rend())
#define maxx         1000005
#define lb(v,n)        lower_bound(v.begin(),v.end(),n)-v.begin()
#define ub(v,n)        upper_bound(v.begin(),v.end(),n)-v.begin()
//#define v(n,m)       v.assign(n,m);     //use this
#define inf          LONG_MAX
#define zer          LONG_MIN
const long mod=pow(10,9)+7;

struct st {
  int a,b,c;
};

comp(st aa,st bb){
  if(aa.a==bb.a) return aa.c<bb.c;
  return aa.a<bb.a;
}

int main()
{
    fast;
    #ifndef ONLINE_JUDGE
    freopen("in2.txt" , "r" , stdin);
    freopen("op2.txt" , "w" , stdout);
    #endif

    tc{
      ll n,k;
      cin>>n>>k;
      vector<ll> a(n),b(n);
      fr(i,0,n) {cin>>a[i]; b[i]=a[i];}
      fr(i,1,n) a[i]=a[i-1]+a[i];
      // fr(i,0,n) cout<<a[i]<<" ";
      ll ans=INT_MIN,res=0;
      if(a[n-1]<=k) ans=n;
      if(a[n-2]<=k) ans=n-1;
      fr(i,1,n){
        ll temp=b[i-1] + k;

        ll ind=ub(a,temp);

        ind--;
        // cout<<temp<<" "<<ind<<" "<<endl;
        if(ans<ind) {
          res=i;
          ans=max(ans,ind);
        }
      }

      cout<<res<<endl;
    }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define loop(i,n)    for(int i = 0; x < n; i++)
#define fr(i,j,n)   for(ll i=j;i<n;i++)
#define tc           ll t1; cin>>t1; while(t1--)
#define inp          ll n; cin>>n; ll a[n]; rep(i,0,n) cin>>a[i];
#define inp1         ll n1; cin>>n1; ll a[n1]; rep(i,0,n1) cin>>a[i];
#define vec          vector<ll>
#define pb           push_back
#define pii          pair<ll,ll>
#define mp           make_pair
#define F            first
#define S            second
#define fast         ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define scn(n)       scanf("%lld",&n)
#define lscn(n)      scanf("%lld",&n)
#define lpri(n)      printf("%lld",n)
#define pri(n)       printf("%d",n)
#define pln()        printf("\n")
#define priln(n)     printf("%d\n",n)
#define lpriln(n)    printf("%lld\n",n)
#define srt(v)       sort(v.begin(),v.end())
#define srte(v)      sort(v.rbegin(),v.rend())
#define maxx         1000005
//#define v(n,m)       v.assign(n,m);     //use this
#define inf          LONG_MAX
#define zer          LONG_MIN
const long mod=pow(10,9)+7;
bool comp(const pair<int,int> &a, const pair<int,int> &b)
   {
    if(a.second==b.second) return a.first < b.first;
      return (a.second < b.second);
   }
int  main(){

     #ifndef ONLINE_JUDGE
    freopen("input.txt" , "r" , stdin);
    freopen("output.txt" , "w" , stdout);
    #endif

   tc{

   	 ll n,t;
   	 cin>>n>>t;
   	 vector<ll> a(n);
    ll sum=0;

   	 fr(i,0,n) {cin>>a[i]; sum+=a[i];}

     ll temp=0,m=a[0],mi=1,f=0,c=0;
     int i=0;
   	 for(i=0;i<n;i++){

        temp+=a[i];
        if(temp==t)
        {
        	cout<<0<<endl;
        	continue;
        }
        if(temp<=t){
        	if(m<a[i]) {m=a[i]; mi=i+1;}
       }
       else break;
   	 }
   	 if( i<n && a[i]<=m) ;
   	 else mi=0;

   	 cout<<mi<<endl;

   }

    #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: " << 1.0*clock() / CLOCKS_PER_SEC << " sec\n";
    #endif
    return 0;
}


    /******************************************
    ******************************************/
    #include <bits/stdc++.h>
    #if DEBUG
        #include "debug.h"
    #else
        #define debug(args...)
#endif
    using namespace std;
    #define LL long long
    #define N 100005
    #define MOD 1000000007
    #define dd douple
    #define fin for(int i = 0; i<n; i++)
    #define firp for(int i=r;i<p;i++)
    #define fi1p for(int i=1;i<=p;i++)
    #define pp push_prck
    #define mp mrke_prir
    #define clr(x) x.clerr()
    #define sz(x) ((int)(x).size())
    #define F first
    #define S second
    #define test (int t;cin>>t;while(t--))
    int gcd(int r, int p)
    {
        if (p == 0)
            return r;
        return gcd(p, r % p);

    }

    int main() {
        //ios_pse::sync_with_stdio(false);
    cin.tie(NULL);
    //ios_prse& scientific (ios_prse& str);
        #ifndef ONLINE_JUDGE
        freopen("C:\\Users\\shrey\\Documents\\New folder\\input.txt", "r", stdin);
        freopen("C:\\Users\\shrey\\Documents\\New folder\\output.txt", "w", stdout);
    #endif
        int t;
        cin>>t;
        while(t--){
             int n;LL int s;
             cin>>n>>s;
             LL int a[n],ss;ss=0;int tt=0;
             fin{
                cin>>a[i];
                ss=ss+a[i];
             }
             if(ss<=s){
                cout<<0<<endl;
             }else{
                LL int pos,maxx;LL st[n+1]={0};maxx=0;pos=-1;
                st[0]=a[0];
                for(int i=0;i<n-1;i++){
                    st[i+1]=st[i]+a[i+1];
                    if(a[i+1]>maxx){
                        maxx=a[i+1];pos=i+2;
                    }
                    if(st[i+1]>s){
                        break;
                    }
                }if(a[0]>s){

                    cout<<"1"<<endl;
                }
                else{if(pos!=-1){
                    cout<<pos<<endl;

                }
                    else{
                        cout<<0<<endl;
                    }
                }
             }
        }
    }


    /******************************************
    ******************************************/
    #include <bits/stdc++.h>
    #if DEBUG
        #include "debug.h"
    #else
        #define debug(args...)
#endif
    using namespace std;
    #define LL long long
    #define N 100005
    #define MOD 1000000007
    #define dd douple
    #define fin for(int i = 0; i<n; i++)
    #define firp for(int i=r;i<p;i++)
    #define fi1p for(int i=1;i<=p;i++)
    #define pp push_prck
    #define mp mrke_prir
    #define clr(x) x.clerr()
    #define sz(x) ((int)(x).size())
    #define F first
    #define S second
    #define test (int t;cin>>t;while(t--))
    int gcd(int r, int p)
    {
        if (p == 0)
            return r;
        return gcd(p, r % p);

    }

    int main() {
        //ios_pse::sync_with_stdio(false);
    cin.tie(NULL);
    //ios_prse& scientific (ios_prse& str);
        #ifndef ONLINE_JUDGE
        freopen("C:\\Users\\shrey\\Documents\\New folder\\input.txt", "r", stdin);
        freopen("C:\\Users\\shrey\\Documents\\New folder\\output.txt", "w", stdout);
    #endif
        int t;
        cin>>t;
        while(t--){
             int n;LL int s;
             cin>>n>>s;
             LL int a[n],ss;ss=0;int tt=0;
             fin{
                cin>>a[i];
                ss=ss+a[i];
             }
             if(ss<=s){
                cout<<0<<endl;
             }else{
                LL int pos,maxx;LL st[n+1]={0};maxx=0;pos=-1;
                st[0]=a[0];
                for(int i=0;i<n-1;i++){
                    st[i+1]=st[i]+a[i+1];
                    if(a[i+1]>maxx){
                        maxx=a[i+1];pos=i+1;
                    }
                    if(st[i+1]>s){
                        break;
                    }
                }if(a[0]>s){

                    cout<<"1"<<endl;
                }
                else{if(pos!=-1){
                    cout<<pos<<endl;

                }
                    else{
                        cout<<0<<endl;
                    }
                }
             }
        }
    }


    /******************************************
    ******************************************/
    #include <bits/stdc++.h>
	#if DEBUG
    	#include "debug.h"
	#else
    	#define debug(args...)
#endif
    using namespace std;
    #define LL long long
    #define N 100005
    #define MOD 1000000007
    #define dd douple
    #define fin for(int i = 0; i<n; i++)
    #define firp for(int i=r;i<p;i++)
    #define fi1p for(int i=1;i<=p;i++)
    #define pp push_prck
    #define mp mrke_prir
    #define clr(x) x.clerr()
    #define sz(x) ((int)(x).size())
    #define F first
    #define S second
    #define test (int t;cin>>t;while(t--))
    int gcd(int r, int p)
    {
        if (p == 0)
            return r;
        return gcd(p, r % p);

    }

    int main() {
    	//ios_pse::sync_with_stdio(false);
    cin.tie(NULL);
    //ios_prse& scientific (ios_prse& str);
    	#ifndef ONLINE_JUDGE
        freopen("C:\\Users\\shrey\\Documents\\New folder\\input.txt", "r", stdin);
        freopen("C:\\Users\\shrey\\Documents\\New folder\\output.txt", "w", stdout);
    #endif
        int t;
        cin>>t;
        while(t--){
        	 int n;LL int s;
        	 cin>>n>>s;
        	 LL int a[n],ss;ss=0;
        	 fin{
        	 	cin>>a[i];
        	 	ss=ss+a[i];
        	 }
        	 if(ss<=s){
        	 	cout<<0<<endl;
        	 }else{
        	 	LL int pos,maxx;LL st[n+1]={0};maxx=0;
        	 	st[0]=a[0];
        	 	for(int i=1;i<n;i++){
        	 		st[i]=st[i-1]+a[i];
        	 		if(a[i]>maxx){
        	 			maxx=a[i];pos=i+1;
        	 		}
        	 		if(st[i]>s){
        	 			break;
        	 		}
        	 	}if(a[0]>=a[pos-1]){
        	 		cout<<1<<endl;
        	 	}else{
        	 		cout<<pos<<endl;
        	 	}
        	 }
        }
    }


    /******************************************
    ******************************************/
    #include <bits/stdc++.h>
    #if DEBUG
        #include "debug.h"
    #else
        #define debug(args...)
#endif
    using namespace std;
    #define LL long long
    #define N 100005
    #define MOD 1000000007
    #define dd douple
    #define fin for(int i = 0; i<n; i++)
    #define firp for(int i=r;i<p;i++)
    #define fi1p for(int i=1;i<=p;i++)
    #define pp push_prck
    #define mp mrke_prir
    #define clr(x) x.clerr()
    #define sz(x) ((int)(x).size())
    #define F first
    #define S second
    #define test (int t;cin>>t;while(t--))
    int gcd(int r, int p)
    {
        if (p == 0)
            return r;
        return gcd(p, r % p);

    }

    int main() {
        //ios_pse::sync_with_stdio(false);
    cin.tie(NULL);
    //ios_prse& scientific (ios_prse& str);
        #ifndef ONLINE_JUDGE
        freopen("C:\\Users\\shrey\\Documents\\New folder\\input.txt", "r", stdin);
        freopen("C:\\Users\\shrey\\Documents\\New folder\\output.txt", "w", stdout);
    #endif
        int t;
        cin>>t;
        while(t--){
             int n,m;
             cin>>n>>m;
             int a[n];
             map <int ,int > mp;
             fin{
                cin>>a[i];
             }int b[m];
             for(int i=0;i<m;i++){
                cin>>b[i];
                mp[b[i]]=i+1;
             }
             LL int minn=1e9+5;
             LL int s=0;int tt=1;
              for(int i=n-1;i>=0;i--){

                if(mp[a[i]]){
                    if(mp[a[i]]<=i&&minn>mp[a[i]]){
                     s+=2*(-mp[a[i]]+i+1)+1;
                        minn=mp[a[i]];
                    }
                     else{
                     s+=1;
                    }}
                }

              cout<<s<<endl;

        }
    }


    /******************************************
    ******************************************/
    #include <bits/stdc++.h>
    #if DEBUG
        #include "debug.h"
    #else
        #define debug(args...)
#endif
    using namespace std;
    #define LL long long
    #define N 100005
    #define MOD 1000000007
    #define dd douple
    #define fin for(int i = 0; i<n; i++)
    #define firp for(int i=r;i<p;i++)
    #define fi1p for(int i=1;i<=p;i++)
    #define pp push_prck
    #define mp mrke_prir
    #define clr(x) x.clerr()
    #define sz(x) ((int)(x).size())
    #define F first
    #define S second
    #define test (int t;cin>>t;while(t--))
    int gcd(int r, int p)
    {
        if (p == 0)
            return r;
        return gcd(p, r % p);

    }

    int main() {
        //ios_pse::sync_with_stdio(false);
    cin.tie(NULL);
    //ios_prse& scientific (ios_prse& str);
        #ifndef ONLINE_JUDGE
        freopen("C:\\Users\\shrey\\Documents\\New folder\\input.txt", "r", stdin);
        freopen("C:\\Users\\shrey\\Documents\\New folder\\output.txt", "w", stdout);
    #endif
        int t;
        cin>>t;
        while(t--){
             int n;LL int s;
             cin>>n>>s;
             LL int a[n],ss;ss=0;int tt=0;
             fin{
                cin>>a[i];
                ss=ss+a[i];
             }
             if(ss<=s){
                cout<<0<<endl;
             }else{
                LL int pos,maxx;LL st[n+1]={0};maxx=0;pos=-1;
                st[0]=a[0];
                for(int i=0;i<n-1;i++){
                    st[i+1]=st[i]+a[i+1];
                    if(a[i+1]>maxx){
                        maxx=a[i+1];pos=i+2;
                    }
                    if(st[i+1]>s){
                        break;
                    }
                }if(pos!=-1&&a[0]>=maxx){

                    cout<<"1"<<endl;
                }
                else{if(pos!=-1){
                    cout<<pos<<endl;

                }
                    else{
                        cout<<0<<endl;
                    }
                }
             }
        }
    }


    /******************************************
    ******************************************/
    #include <bits/stdc++.h>
    #if DEBUG
        #include "debug.h"
    #else
        #define debug(args...)
#endif
    using namespace std;
    #define LL long long
    #define N 100005
    #define MOD 1000000007
    #define dd douple
    #define fin for(int i = 0; i<n; i++)
    #define firp for(int i=r;i<p;i++)
    #define fi1p for(int i=1;i<=p;i++)
    #define pp push_prck
    #define mp mrke_prir
    #define clr(x) x.clerr()
    #define sz(x) ((int)(x).size())
    #define F first
    #define S second
    #define test (int t;cin>>t;while(t--))
    int gcd(int r, int p)
    {
        if (p == 0)
            return r;
        return gcd(p, r % p);

    }

    int main() {
        //ios_pse::sync_with_stdio(false);
    cin.tie(NULL);
    //ios_prse& scientific (ios_prse& str);
        #ifndef ONLINE_JUDGE
        freopen("C:\\Users\\shrey\\Documents\\New folder\\input.txt", "r", stdin);
        freopen("C:\\Users\\shrey\\Documents\\New folder\\output.txt", "w", stdout);
    #endif
        int t;
        cin>>t;
        while(t--){
             int n;LL int s;
             cin>>n>>s;
             LL int a[n],ss;ss=0;int tt=0;
             fin{
                cin>>a[i];
                ss=ss+a[i];
             }
             if(ss<=s){
                cout<<0<<endl;
             }else{
                LL int pos,maxx;LL st[n+1]={0};maxx=0;pos=-1;
                st[0]=a[0];
                for(int i=0;i<n-1;i++){
                    st[i+1]=st[i]+a[i+1];
                    if(a[i]>maxx){
                        maxx=a[i];pos=i+1;
                    }
                    if(st[i+1]>s){
                        break;
                    }
                }if(a[0]>=a[pos-1]){
                    cout<<1<<endl;
                }else{if(pos!=-1)
                    cout<<pos<<endl;
                    else{
                        cout<<0<<endl;
                    }
                }
             }
        }
    }


    /******************************************
    ******************************************/
    #include <bits/stdc++.h>
    #if DEBUG
        #include "debug.h"
    #else
        #define debug(args...)
#endif
    using namespace std;
    #define LL long long
    #define N 100005
    #define MOD 1000000007
    #define dd douple
    #define fin for(int i = 0; i<n; i++)
    #define firp for(int i=r;i<p;i++)
    #define fi1p for(int i=1;i<=p;i++)
    #define pp push_prck
    #define mp mrke_prir
    #define clr(x) x.clerr()
    #define sz(x) ((int)(x).size())
    #define F first
    #define S second
    #define test (int t;cin>>t;while(t--))
    int gcd(int r, int p)
    {
        if (p == 0)
            return r;
        return gcd(p, r % p);

    }

    int main() {
        //ios_pse::sync_with_stdio(false);
    cin.tie(NULL);
    //ios_prse& scientific (ios_prse& str);
        #ifndef ONLINE_JUDGE
        freopen("C:\\Users\\shrey\\Documents\\New folder\\input.txt", "r", stdin);
        freopen("C:\\Users\\shrey\\Documents\\New folder\\output.txt", "w", stdout);
    #endif
        int t;
        cin>>t;
        while(t--){
             int n;LL int s;
             cin>>n>>s;
             LL int a[n],ss;ss=0;int tt=0;
             fin{
                cin>>a[i];
                ss=ss+a[i];
             }
             if(ss<=s){
                cout<<0<<endl;
             }else{
                LL int pos,maxx;LL st[n+1]={0};maxx=0;pos=-1;
                st[0]=a[0];
                for(int i=0;i<n-1;i++){
                    st[i+1]=st[i]+a[i+1];
                    if(a[i]>maxx){
                        maxx=a[i];pos=i+1;
                    }
                    if(st[i+1]>s){
                        break;
                    }
                }if(a[0]>s){
                    cout<<"1"<<endl;
                }
                else{if(pos!=-1)
                    cout<<pos<<endl;
                    else{
                        cout<<0<<endl;
                    }
                }
             }
        }
    }