#include <iostream>
#include<vector>
using namespace std;

int main() {
    // your code goes here
    int t;
    cin>>t;
    while(t--)
    {
        int n,p=0;
        cin>>n;
      int a[n];
        int c=0;
        int b[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i]>>b[i];
        }
        if(n==1)
        {
            if(a[0]>=b[0])
            {
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }

        }
         for(int i=0;i<n;i++)
        {
            if(a[i]>=b[i])
            {
                p++;
            }
            else{
                p=0;
                 cout<<"NO"<<endl;
                 break;
            }
    }
         if(p>0 && n!=1){
        for(int i=0;i<n-1;i++)
        {
            if(b[i+1]>b[i])
            {
                if(a[i+1]>a[i])
                {
                    c=1;
                }
                else if(a[i+1]<=a[i])
                {
                    c=0;
                    cout<<"NO"<<endl;
                    break;
                }
            }
            else if(b[i+1]==b[i])
            {
                 if(a[i+1]>=a[i])
                {
                    c=1;
                }
                else if(a[i+1]<a[i])
                {
                    c=0;
                    cout<<"NO"<<endl;
                    break;
                }
            }
          else  if(a[i+1]<a[i])
            {
                c=0;
                cout<<"NO"<<endl;
                    break;

            }
           else if(b[i+1]<b[i])
            {
                c=0;
                cout<<"NO"<<endl;
                    break;
            }
          else  if(a[i+1]>a[i])
            {
                if(b[i+1]>=b[i])
                {
                    c=1;
                }
                else
                {
                    c=0;
                    cout<<"NO"<<endl;
                    break;
                }
            }
              else  if(a[i+1]==a[i])
            {
                if(b[i+1]==b[i])
                {
                    c=1;
                }
                else
                {
                    c=0;
                    cout<<"NO"<<endl;
                    break;
                }
            }

        }
        if(c==1)
        {
             cout<<"YES"<<endl;

        }
    }
}
    return 0;
}


#include <iostream>
#include<vector>
using namespace std;

int main() {
    // your code goes here
    int t;
    cin>>t;
    while(t--)
    {
        int n,p=0;
        cin>>n;
      int a[n];
        int c=0;
        int b[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i]>>b[i];
        }
        if(n==1)
        {
            if(a[0]>=b[0])
            {
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }

        }
         for(int i=0;i<n;i++)
        {
            if(a[i]>=b[i])
            {
                p++;
            }
            else{
                p=0;
                 cout<<"NO"<<endl;
            }
    }
         if(p>0 && n!=1){
        for(int i=0;i<n-1;i++)
        {
            if(b[i+1]>b[i])
            {
                if(a[i+1]>a[i])
                {
                    c=1;
                }
                else if(a[i+1]<=a[i])
                {
                    c=0;
                    cout<<"NO"<<endl;
                    break;
                }
            }
            else if(b[i+1]==b[i])
            {
                 if(a[i+1]>=a[i])
                {
                    c=1;
                }
                else if(a[i+1]<a[i])
                {
                    c=0;
                    cout<<"NO"<<endl;
                    break;
                }
            }
          else  if(a[i+1]<a[i])
            {
                c=0;
                cout<<"NO"<<endl;
                    break;

            }
           else if(b[i+1]<b[i])
            {
                c=0;
                cout<<"NO"<<endl;
                    break;
            }
          else  if(a[i+1]>a[i])
            {
                if(b[i+1]>=b[i])
                {
                    c=1;
                }
                else
                {
                    c=0;
                    cout<<"NO"<<endl;
                    break;
                }
            }
              else  if(a[i+1]==a[i])
            {
                if(b[i+1]==b[i])
                {
                    c=1;
                }
                else
                {
                    c=0;
                    cout<<"NO"<<endl;
                    break;
                }
            }

        }
        if(c==1)
        {
             cout<<"YES"<<endl;

        }
    }
}
    return 0;
}


#include <iostream>
#include<vector>
using namespace std;

int main() {
    // your code goes here
    int t;
    cin>>t;
    while(t--)
    {
        int n,p=0;
        cin>>n;
        int a[n];
        int c=0;
        int b[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i]>>b[i];
        }
        if(n==1)
        {
            cout<<"YES"<<endl;
        }
        else{
        for(int i=0;i<n-1;i++)
        {
            if(b[i+1]>b[i])
            {
                if(a[i+1]>a[i])
                {
                    c=1;
                }
                else if(a[i+1]<=a[i])
                {
                    c=0;
                    cout<<"NO"<<endl;
                    break;
                }
            }
          else  if(a[i+1]<a[i])
            {
                c=0;
                cout<<"NO"<<endl;
                    break;

            }
           else if(b[i+1]<b[i])
            {
                c=0;
                cout<<"NO"<<endl;
                    break;
            }
          else  if(a[i+1]>a[i])
            {
                if(b[i+1]>=b[i])
                {
                    c=1;
                }
                else
                {
                    c=0;
                    cout<<"NO"<<endl;
                    break;
                }
            }
              else  if(a[i+1]==a[i])
            {
                if(b[i+1]==b[i])
                {
                    c=1;
                }
                else
                {
                    c=0;
                    cout<<"NO"<<endl;
                    break;
                }
            }

        }
        if(c==1)
        {
             cout<<"YES"<<endl;

        }
    }
}
    return 0;
}


#include <iostream>
#include<vector>
using namespace std;

int main() {
    // your code goes here
    int t;
    cin>>t;
    while(t--)
    {
        int n,p=0;
        cin>>n;
      int a[n];
        int c=0;
        int b[n];
        for(int i=0;i<n;i++)
        {
            cin>>a[i]>>b[i];
        }
         for(int i=0;i<n;i++)
        {
            if(a[i]>=b[i])
            {
                p++;
            }
            else{
                p=0;
                 cout<<"NO"<<endl;
                 break;
            }
    }
        if(n==1 && p!=0)
        {
            if(a[0]>=b[0])
            {
            cout<<"YES"<<endl;
        }
        else{
            cout<<"NO"<<endl;
        }

        }

         if(p==n){
        for(int i=0;i<n-1;i++)
        {
            if(b[i+1]>b[i])

            {
                long long int x=a[i+1]-a[i];
                if(a[i+1]>a[i] && x>=(b[i+1]-b[i]))
                {
                    c=1;
                }
                else
                {
                    c=0;
                    cout<<"NO"<<endl;
                    break;
                }
            }
             if(b[i+1]==b[i])
            {
                 if(a[i+1]>=a[i])
                {
                    c=1;
                }
                else if(a[i+1]<a[i])
                {
                    c=0;
                    cout<<"NO"<<endl;
                    break;
                }
            }
           if(a[i+1]<a[i])
            {
                c=0;
                cout<<"NO"<<endl;
                    break;

            }
            if(b[i+1]<b[i])
            {
                c=0;
                cout<<"NO"<<endl;
                    break;
            }
           if(a[i+1]>a[i])
            {
                if(b[i+1]>=b[i])
                {
                    c=1;
                }
                else
                {
                    c=0;
                    cout<<"NO"<<endl;
                    break;
                }
            }
              if(a[i+1]==a[i])
            {
                if(b[i+1]==b[i])
                {
                    c=1;
                }
                else
                {
                    c=0;
                    cout<<"NO"<<endl;
                    break;
                }
            }

        }
        if(c==1)
        {
             cout<<"YES"<<endl;

        }
    }
}
    return 0;
}


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

#define ll long long
#define mx 100005

int n,m;
char ch[mx];
int ar[mx];

void solve()
{
   scanf("%d",&n);
   bool f=true;
   int lastx=0,lasty=0;
   for(int i=1;i<=n;i++)
   {
       int x,y;
       scanf("%d%d",&x,&y);
       if(x<lastx || y<lasty)f=false;
       if(i==1 && y>x)f=false;
       if(y>x)lastx=y*2;
       else
       {
           if(y!=0)lastx=x+y*2;
       }
       lasty+=y;
   }
   if(f)printf("YES\n");
   else printf("NO\n");
}

int main()
{
    int t=1;
    scanf("%d",&t);
    while(t--)solve();
    return 0;
}


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

#define ll long long
#define mx 100005

int n,m;
char ch[mx];
int ar[mx];

void solve()
{
   scanf("%d",&n);
   bool f=true;
   int lastx=0,lasty=0;
   for(int i=1;i<=n;i++)
   {
       int x,y;
       scanf("%d%d",&x,&y);
       if(x<lastx || y<lasty)f=false;
       if(i==1 && y>x)f=false;
       if(y>x)lastx+=y*2;
       else
       {
           if(y!=0)lastx+=x+y*2;
       }
       lasty+=y;
   }
   if(f)printf("YES\n");
   else printf("NO\n");
}

int main()
{
    int t=1;
    scanf("%d",&t);
    while(t--)solve();
    return 0;
}


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

#define ll long long
#define mx 100005

int n,m;
char ch[mx];
int ar[mx];

void solve()
{
   scanf("%d",&n);
   bool f=true;
   int lastx=-1,lasty=-1;
   for(int i=1;i<=n;i++)
   {
       int x,y;
       scanf("%d%d",&x,&y);
       if(x<lastx || y<lasty)f=false;
       if(x<y)
       {
           if(i==1)f=false;
           else {
             if(x-lastx<y-lasty)f=false;
           }
       }
       lastx=x;
       lasty=y;
   }
   if(f)printf("YES\n");
   else printf("NO\n");
}

int main()
{
    int t=1;
    scanf("%d",&t);
    while(t--)solve();
    return 0;
}


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

#define ll long long
#define mx 100005

int n,m;
char ch[mx];
int ar[mx];

void solve()
{
   scanf("%d",&n);
   bool f=true;
   int lastx=0,lasty=0;
   for(int i=1;i<=n;i++)
   {
       int x,y;
       scanf("%d%d",&x,&y);
       if(x<lastx || y<lasty)f=false;
       if(i==1 && y>x)f=false;
       if(y>x)lastx+=y*2;
       else
       {
           if(y!=0)lastx+=x+y;
       }
       lasty+=y;
   }
   if(f)printf("YES\n");
   else printf("NO\n");
}

int main()
{
    int t=1;
    scanf("%d",&t);
    while(t--)solve();
    return 0;
}


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

#define ll long long
#define mx 100005

int n,m;
char ch[mx];
int ar[mx];

void solve()
{
   scanf("%d",&n);
   bool f=true;
   int lastx=-1,lasty=-1;
   for(int i=1;i<=n;i++)
   {
       int x,y;
       scanf("%d%d",&x,&y);
       if(x<lastx || y<lasty)f=false;
       lastx=x+y;
       if(y>x)lastx+=(y-x)*2;
       lasty=y;
   }
   if(f)printf("YES\n");
   else printf("NO\n");
}

int main()
{
    int t=1;
    scanf("%d",&t);
    while(t--)solve();
    return 0;
}


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

#define ll long long
#define mx 100005

int n,m;
char ch[mx];
int ar[mx];

void solve()
{
   int n,i,fi,cl;
        bool f=true;
        scanf("%d",&n);
        pair<int,int>p[n+5];

        for(i=0;i<n;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            p[i]={x,y};
        }
        for(i=0;i<n;i++)
        {
            if(i==0 && p[i].first==0 &&  p[i].second==0)
            {
                f=true;
            }
            else if(i==0 && p[i].first!=0 &&  p[i].second==0)
            {
                f=true;
            }
            else if(i==0 && p[i].first!=0 &&  p[i].second!=0 && p[i].first>=p[i].second)
            {
                f=true;
            }
            else if(i>0 && p[i].first>p[i-1].first && p[i].second>=p[i-1].second && p[i].first>=p[i].second)
            {
                f=true;
            }
            else if(i>0 && p[i].first==p[i-1].first && p[i].second==p[i-1].second && p[i].first>=p[i].second)
            {
                f=true;
            }
            else
            {
                f=false;
                break;
            }
        }
        if(f) printf("YES\n");
        else printf("NO\n");
}

int main()
{
    int t=1;
    scanf("%d",&t);
    while(t--)solve();
    return 0;
}


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

#define ll long long
#define mx 100005

int n,m;
char ch[mx];
int ar[mx];

void solve()
{
   scanf("%d",&n);
   bool f=true;
   int lastx=-1,lasty=-1;
   for(int i=1;i<=n;i++)
   {
       int x,y;
       scanf("%d%d",&x,&y);
       if(x<lastx || y<lasty)f=false;
       lastx=x+y;
       lasty=y;
   }
   if(f)printf("YES\n");
   else printf("NO\n");
}

int main()
{
    int t=1;
    scanf("%d",&t);
    while(t--)solve();
    return 0;
}


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

#define ll long long
#define mx 100005

int n,m;
char ch[mx];
int ar[mx];

void solve()
{
   scanf("%d",&n);
   bool f=true;
   int lastx=-1,lasty=-1;
   for(int i=1;i<=n;i++)
   {
       int x,y;
       scanf("%d%d",&x,&y);
       if(x<lastx || y<lasty)f=false;
       if(i>1 && x-lastx<y-lasty)f=false;
       if(i==1 && x<y)f=false;
       lastx=x;
       lasty=y;
   }
   if(f)printf("YES\n");
   else printf("NO\n");
}

int main()
{
    int t=1;
    scanf("%d",&t);
    while(t--)solve();
    return 0;
}


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

#define ll long long
#define mx 100005

int n,m;
char ch[mx];
int ar[mx];

void solve()
{
   scanf("%d",&n);
   bool f=true;
   int lastx=-1,lasty=-1;
   for(int i=1;i<=n;i++)
   {
       int x,y;
       scanf("%d%d",&x,&y);
       if(x<lastx || y<lasty)f=false;
       if(x<y)
       {
           if(i==1)f=false;
           else {
             if(x-lastx<y-x)f=false;
           }
       }
       lastx=x;
       lasty=y;
   }
   if(f)printf("YES\n");
   else printf("NO\n");
}

int main()
{
    int t=1;
    scanf("%d",&t);
    while(t--)solve();
    return 0;
}


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

#define fr(i,a) for(int  i=0;i<a;i++)
#define forn(i,a,n) for(int i = a; i < n ;i++)
#define Sort(a) sort(a.begin(),a.end())
#define Rev(k)  reverse(k.begin(),k.end())
#define Sz(x) x.size()
#define Show(v) for(int i =0 ; i < v.size();i++) cout<<v[i] //only for sting and vector
#define Mod 1000000007
#define Fi first
#define Sc second
#define pb push_back
#define Ios ios::sync_with_stdio(false)
#define Tie cin.tie(0)
#define inf 0x3f3f3f3f
#define mk make_pair
template<typename T, typename V> inline void mn(T &x, V y) { if(y < x) x = y; }
template<typename T, typename V> inline void mx(T &x, V y) { if(x < y) x = y; }
//const int MAXN = 200100;
typedef long long  ll;

bool help(int a[],int b[],int n ){
    fr(i,n){
        if(a[i]<b[i]){
            return 0 ;
        }
        if(i!=0){
            if(a[i-1]>=a[i]){
                return false ;
            }
//            if(a[i-1]==a[i]){
//                return b[i-1]==b[i] ;
//
//            }

            if(b[i-1]>b[i])
                return false ;
        }
    }
    return true ;
}

int main()
{
    Ios;
    Tie;
    int t;
    cin>>t;
    while(t--){
    int n ;
    cin>>n;
    int a[n] ,b[n] ;
    fr(i,n)cin>>a[i]>>b[i] ;

    if(help(a,b,n))
        cout<<"YES" ;
    else
        cout<<"No";
    cout<<endl;
    }
}


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

#define fr(i,a) for(int  i=0;i<a;i++)
#define forn(i,a,n) for(int i = a; i < n ;i++)
#define Sort(a) sort(a.begin(),a.end())
#define Rev(k)  reverse(k.begin(),k.end())
#define Sz(x) x.size()
#define Show(v) for(int i =0 ; i < v.size();i++) cout<<v[i] //only for sting and vector
#define Mod 1000000007
#define Fi first
#define Sc second
#define pb push_back
#define Ios ios::sync_with_stdio(false)
#define Tie cin.tie(0)
#define inf 0x3f3f3f3f
#define mk make_pair
template<typename T, typename V> inline void mn(T &x, V y) { if(y < x) x = y; }
template<typename T, typename V> inline void mx(T &x, V y) { if(x < y) x = y; }
//const int MAXN = 200100;
typedef long long  ll;

bool help(int a[],int b[],int n ){
    fr(i,n){
        if(a[i]<b[i]){
            return 0 ;
        }
        if(i!=0){
            if(a[i-1]>a[i]){
                return false ;
            }
            if(a[i-1]==a[i]){
                return b[i-1]==b[i] ;

            }

            if(b[i-1]>b[i])
                return false ;
        }
    }
    return true ;
}

int main()
{
    Ios;
    Tie;
    int t;
    cin>>t;
    while(t--){
    int n ;
    cin>>n;
    int a[n] ,b[n] ;
    fr(i,n)cin>>a[i]>>b[i] ;

    if(help(a,b,n))
        cout<<"YES" ;
    else
        cout<<"No";
    cout<<endl;
    }
}


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

#define fr(i,a) for(int  i=0;i<a;i++)
#define forn(i,a,n) for(int i = a; i < n ;i++)
#define Sort(a) sort(a.begin(),a.end())
#define Rev(k)  reverse(k.begin(),k.end())
#define Sz(x) x.size()
#define Show(v) for(int i =0 ; i < v.size();i++) cout<<v[i] //only for sting and vector
#define Mod 1000000007
#define Fi first
#define Sc second
#define pb push_back
#define Ios ios::sync_with_stdio(false)
#define Tie cin.tie(0)
#define inf 0x3f3f3f3f
#define mk make_pair
template<typename T, typename V> inline void mn(T &x, V y) { if(y < x) x = y; }
template<typename T, typename V> inline void mx(T &x, V y) { if(x < y) x = y; }
//const int MAXN = 200100;
typedef long long  ll;

bool help(int a[],int b[],int n ){
    fr(i,n){
        if(a[i]<b[i]){
            return 0 ;
        }
        if(i!=0){
            if(a[i-1]>a[i]){
                return false ;
            }
            if(b[i-1]>b[i])
                return false ;
        }
    }
    return true ;
}

int main()
{
    Ios;
    Tie;
    int t;
    cin>>t;
    while(t--){
    int n ;
    cin>>n;
    int a[n] ,b[n] ;
    fr(i,n)cin>>a[i]>>b[i] ;

    if(help(a,b,n))
        cout<<"YES" ;
    else
        cout<<"No";
    cout<<endl;
    }
}


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

#define fr(i,a) for(int  i=0;i<a;i++)
#define forn(i,a,n) for(int i = a; i < n ;i++)
#define Sort(a) sort(a.begin(),a.end())
#define Rev(k)  reverse(k.begin(),k.end())
#define Sz(x) x.size()
#define Show(v) for(int i =0 ; i < v.size();i++) cout<<v[i] //only for sting and vector
#define Mod 1000000007
#define Fi first
#define Sc second
#define pb push_back
#define Ios ios::sync_with_stdio(false)
#define Tie cin.tie(0)
#define inf 0x3f3f3f3f
#define mk make_pair
template<typename T, typename V> inline void mn(T &x, V y) { if(y < x) x = y; }
template<typename T, typename V> inline void mx(T &x, V y) { if(x < y) x = y; }
//const int MAXN = 200100;
typedef long long  ll;

bool help(int a[],int b[],int n ){
    fr(i,n){
        if(a[i]<b[i]){
            return 0 ;
        }
        if(i!=0){
            if(a[i-1]>a[i]){
                return false ;
            }

            if(b[i-1]>b[i])
                return false ;
            if(a[i-1]==a[i]){
                return b[i-1]==b[i] ;

            }
            if(a[i]-a[i-1]<b[i]-b[i-1])return 0;

        }
    }
    return true ;
}

int main()
{
    Ios;
    Tie;
    int t;
    cin>>t;
    while(t--){
    int n ;
    cin>>n;
    int a[n] ,b[n] ;
    fr(i,n)
        cin>>a[i]>>b[i] ;

    if(help(a,b,n))
        cout<<"YES" ;
    else
        cout<<"NO";
    cout<<endl;
    }
}


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

#define fr(i,a) for(int  i=0;i<a;i++)
#define forn(i,a,n) for(int i = a; i < n ;i++)
#define Sort(a) sort(a.begin(),a.end())
#define Rev(k)  reverse(k.begin(),k.end())
#define Sz(x) x.size()
#define Show(v) for(int i =0 ; i < v.size();i++) cout<<v[i] //only for sting and vector
#define Mod 1000000007
#define Fi first
#define Sc second
#define pb push_back
#define Ios ios::sync_with_stdio(false)
#define Tie cin.tie(0)
#define inf 0x3f3f3f3f
#define mk make_pair
template<typename T, typename V> inline void mn(T &x, V y) { if(y < x) x = y; }
template<typename T, typename V> inline void mx(T &x, V y) { if(x < y) x = y; }
//const int MAXN = 200100;
typedef long long  ll;

bool help(int a[],int b[],int n ){
    fr(i,n){
        if(a[i]<b[i]){
            return 0 ;
        }
        if(i!=0){
            if(a[i-1]>a[i]){
                return false ;
            }
            if(a[i-1]==a[i]){
                return b[i-1]==b[i] ;

            }
            if(a[i]-a[i-1]<b[i]-b[i-1])return 0;

            if(b[i-1]>b[i])
                return false ;
        }
    }
    return true ;
}

int main()
{
    Ios;
    Tie;
    int t;
    cin>>t;
    while(t--){
    int n ;
    cin>>n;
    int a[n] ,b[n] ;
    fr(i,n)cin>>a[i]>>b[i] ;

    if(help(a,b,n))
        cout<<"YES" ;
    else
        cout<<"No";
    cout<<endl;
    }
}


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

#define fr(i,a) for(int  i=0;i<a;i++)
#define forn(i,a,n) for(int i = a; i < n ;i++)
#define Sort(a) sort(a.begin(),a.end())
#define Rev(k)  reverse(k.begin(),k.end())
#define Sz(x) x.size()
#define Show(v) for(int i =0 ; i < v.size();i++) cout<<v[i] //only for sting and vector
#define Mod 1000000007
#define Fi first
#define Sc second
#define pb push_back
#define Ios ios::sync_with_stdio(false)
#define Tie cin.tie(0)
#define inf 0x3f3f3f3f
#define mk make_pair
template<typename T, typename V> inline void mn(T &x, V y) { if(y < x) x = y; }
template<typename T, typename V> inline void mx(T &x, V y) { if(x < y) x = y; }
//const int MAXN = 200100;
typedef long long  ll;

bool help(int a[],int b[],int n ){
    fr(i,n){
        if(a[i]<b[i]){
            return 0 ;
        }
        if(i!=0){
            if(a[i-1]>a[i]){
                return false ;
            }

            if(b[i-1]>b[i])
                return false ;
            if(a[i-1]==a[i]){
                return b[i-1]==b[i] ;

            }
            if(a[i]-a[i-1]<b[i]-b[i-1])return 0;

        }
    }
    return true ;
}

int main()
{
    Ios;
    Tie;
    int t;
    cin>>t;
    while(t--){
    int n ;
    cin>>n;
    int a[n] ,b[n] ;
    fr(i,n)cin>>a[i]>>b[i] ;

    if(help(a,b,n))
        cout<<"YES" ;
    else
        cout<<"No";
    cout<<endl;
    }
}


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

#define fr(i,a) for(int  i=0;i<a;i++)
#define forn(i,a,n) for(int i = a; i < n ;i++)
#define Sort(a) sort(a.begin(),a.end())
#define Rev(k)  reverse(k.begin(),k.end())
#define Sz(x) x.size()
#define Show(v) for(int i =0 ; i < v.size();i++) cout<<v[i] //only for sting and vector
#define Mod 1000000007
#define Fi first
#define Sc second
#define pb push_back
#define Ios ios::sync_with_stdio(false)
#define Tie cin.tie(0)
#define inf 0x3f3f3f3f
#define mk make_pair
template<typename T, typename V> inline void mn(T &x, V y) { if(y < x) x = y; }
template<typename T, typename V> inline void mx(T &x, V y) { if(x < y) x = y; }
//const int MAXN = 200100;
typedef long long  ll;

bool help(int a[],int b[],int n ){
    if(a[0]<b[0])return false ;
    forn(i,1,n){

        if(a[i]-a[i-1]<b[i]-b[i-1])
            return false;

            if(a[i-1]>a[i]){
                return false ;
            }

            if(b[i-1]>b[i])
                return false ;

    }
    return true ;
}

int main()
{
    Ios;
    Tie;
    int t;
    cin>>t;
    while(t--){
    int n ;
    cin>>n;
    int a[n] ,b[n] ;
    fr(i,n)
        cin>>a[i]>>b[i] ;

    if(help(a,b,n))
        cout<<"YES" ;
    else
        cout<<"NO";
    cout<<endl;
    }
}


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

#define fr(i,a) for(int  i=0;i<a;i++)
#define forn(i,a,n) for(int i = a; i < n ;i++)
#define Sort(a) sort(a.begin(),a.end())
#define Rev(k)  reverse(k.begin(),k.end())
#define Sz(x) x.size()
#define Show(v) for(int i =0 ; i < v.size();i++) cout<<v[i] //only for sting and vector
#define Mod 1000000007
#define Fi first
#define Sc second
#define pb push_back
#define Ios ios::sync_with_stdio(false)
#define Tie cin.tie(0)
#define inf 0x3f3f3f3f
#define mk make_pair
template<typename T, typename V> inline void mn(T &x, V y) { if(y < x) x = y; }
template<typename T, typename V> inline void mx(T &x, V y) { if(x < y) x = y; }
//const int MAXN = 200100;
typedef long long  ll;

bool help(int a[],int b[],int n ){
    fr(i,n){
        if(a[i]<b[i]){
            return 0 ;
        }
        if(i!=0){
            if(a[i-1]>a[i]){
                return false ;
            }
            if(b[i-1]!=b[i]-1)
                return false ;
        }
    }
    return true ;
}

int main()
{
    Ios;
    Tie;
    int t;
    cin>>t;
    while(t--){
    int n ;
    cin>>n;
    int a[n] ,b[n] ;
    fr(i,n)cin>>a[i]>>b[i] ;

    if(help(a,b,n))
        cout<<"YES" ;
    else
        cout<<"No";
    cout<<endl;
    }
}


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

#define fr(i,a) for(int  i=0;i<a;i++)
#define forn(i,a,n) for(int i = a; i < n ;i++)
#define Sort(a) sort(a.begin(),a.end())
#define Rev(k)  reverse(k.begin(),k.end())
#define Sz(x) x.size()
#define Show(v) for(int i =0 ; i < v.size();i++) cout<<v[i] //only for sting and vector
#define Mod 1000000007
#define Fi first
#define Sc second
#define pb push_back
#define Ios ios::sync_with_stdio(false)
#define Tie cin.tie(0)
#define inf 0x3f3f3f3f
#define mk make_pair
template<typename T, typename V> inline void mn(T &x, V y) { if(y < x) x = y; }
template<typename T, typename V> inline void mx(T &x, V y) { if(x < y) x = y; }
//const int MAXN = 200100;
typedef long long  ll;

bool help(int a[],int b[],int n ){
    fr(i,n){

        if(a[i]-a[i-1]<b[i]-b[i-1])
            return false;

            if(a[i-1]>a[i]){
                return false ;
            }

            if(b[i-1]>b[i])
                return false ;

    }
    return true ;
}

int main()
{
    Ios;
    Tie;
    int t;
    cin>>t;
    while(t--){
    int n ;
    cin>>n;
    int a[n] ,b[n] ;
    fr(i,n)
        cin>>a[i]>>b[i] ;

    if(help(a,b,n))
        cout<<"YES" ;
    else
        cout<<"NO";
    cout<<endl;
    }
}


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

#define fr(i,a) for(int  i=0;i<a;i++)
#define forn(i,a,n) for(int i = a; i < n ;i++)
#define Sort(a) sort(a.begin(),a.end())
#define Rev(k)  reverse(k.begin(),k.end())
#define Sz(x) x.size()
#define Show(v) for(int i =0 ; i < v.size();i++) cout<<v[i] //only for sting and vector
#define Mod 1000000007
#define Fi first
#define Sc second
#define pb push_back
#define Ios ios::sync_with_stdio(false)
#define Tie cin.tie(0)
#define inf 0x3f3f3f3f
#define mk make_pair
template<typename T, typename V> inline void mn(T &x, V y) { if(y < x) x = y; }
template<typename T, typename V> inline void mx(T &x, V y) { if(x < y) x = y; }
//const int MAXN = 200100;
typedef long long  ll;

bool help(int a[],int b[],int n ){
    fr(i,n){
        if(a[i]<b[i]){
            return 0 ;
        }
        if(i!=0){
            if(a[i-1]>a[i]){
                return false ;
            }
            if(!(a[i-1]==a[i]&&b[i-1]==b[i]))return 0;
            if(b[i-1]>b[i])
                return false ;
        }
    }
    return true ;
}

int main()
{
    Ios;
    Tie;
    int t;
    cin>>t;
    while(t--){
    int n ;
    cin>>n;
    int a[n] ,b[n] ;
    fr(i,n)cin>>a[i]>>b[i] ;

    if(help(a,b,n))
        cout<<"YES" ;
    else
        cout<<"No";
    cout<<endl;
    }
}


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

int main() {
	int t;
	cin>>t;
	while(t--){
	    int n,i;
	    cin>>n;
	    int a[n][2],ct=0;
	    for(i=0;i<n;i++){
	        cin>>a[i][0]>>a[i][1];
	    }
	    int flag=0;
	    for(i=1;i<n;i++){
	        if(((a[i][0]==a[i-1][0]) && ((a[i][1]>a[i-1][1])||(a[i][1]<a[i-1][1]))) || (a[i][0]<a[i-1][0])){
	            flag=1;
	            break;
	        }

	    }
	    //cout<<ct<<" ";
	    if(flag)
	        cout<<"NO"<<endl;
	    else
	        cout<<"YES"<<endl;
	}
	return 0;
}


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

int main() {
	int t;
	cin>>t;
	while(t--){
	    int n,i;
	    cin>>n;
	    int a[n][2],ct=0;
	    for(i=0;i<n;i++){
	        cin>>a[i][0]>>a[i][1];
	    }
	    int flag=0;
	    if(n==1){
	        if(a[0][0]>=a[0][1])
	            cout<<"YES"<<endl;
	        else
	            cout<<"NO"<<endl;
	    }
	    else{
    	    for(i=0;i<n-1;i++){
    	        if(a[i][0]<a[i][1]){
    	            flag=1;
    	            break;
    	        }
    	        else if((a[i+1][0]-a[i][0])<(a[i+1][1]-a[i][1])){
    	            flag=1;
    	            break;
    	        }
    	        else if((a[i+1][0]==a[i][0]) && (a[i+1][1]<a[i][1])){
    	            flag=1;
    	            break;
    	        }
    	    }
    	    //cout<<ct<<" ";
    	    if(flag)
    	        cout<<"NO"<<endl;
    	    else
    	        cout<<"YES"<<endl;
    	}

	}
	return 0;
}


#include <iostream>
using namespace std;

int main() {
	int t;
	cin>>t;
	while(t--){
	    int n,p=0,c=0,f=0;
	    cin>>n;
	    while(n--){
	        int x,y;
	        cin>>x>>y;
	        if(x<p || y<c || (y-c)>(x-p)){
	            f=1;
	        }
	        p=x,c=y;
	    }
	    if(f){
	        cout<<"NO"<<"\n";
	    }
	    else{
	        cout<<"YES"<<"\n";
	    }
	}
	return 0;
}


    #include<iostream>

        int main(){
        	int t; //no. of test cases
        	std::cin>>t;

        	for(;t>0;--t){
        	    int n,prev_plays,prev_clears,curr_plays,curr_clears,flag=0; //required variables
        		std::cin>>n;
        		std::cin>>prev_plays>>prev_clears;
        		--n;
        		flag=0;
        		if(prev_plays<prev_clears)
        		    flag=1;
        		for(;n>0;--n){
        			std::cin>>curr_plays>>curr_clears;
        			if((curr_plays<prev_plays)||(curr_clears<prev_clears)||((curr_plays-curr_clears)<(prev_plays-prev_clears))){
        				flag=1;
        				break;
        			}
        			prev_plays=curr_plays;
        			prev_clears=curr_clears;
        		}
        		if(!flag){
        			std::cout<<"YES\n";
        		}
        		else
        			std::cout<<"NO\n";
        	}
        	return 0;
        }


/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include<iostream>

int main(){
	int t; //no. of test cases
	std::cin>>t;
	int n,prev_plays,prev_clears,curr_plays,curr_clears,flag=0; //required variables
	for(;t>0;--t){
	    flag=0;
		std::cin>>n;
		std::cin>>prev_plays>>prev_clears;
		--n;
		for(;n>0;--n){
			std::cin>>curr_plays>>curr_clears;
			if((curr_plays<prev_plays)||(curr_clears<prev_clears)||((curr_plays-curr_clears)<(prev_plays-prev_clears))){
				flag=1;
				break;
			}
			prev_plays=curr_plays;
			prev_clears=curr_clears;
		}
		if(!flag){
			std::cout<<"YES\n";
		}
		else
			std::cout<<"NO\n";
	}
	return 0;
}


/******************
 *AUTHOR: speckrel*
 ******************/

//******************************************************************************
#include "bits/stdc++.h"
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define fpowll fpow<long long>
#define fpowi fpow<int>
#define rep(i,a,b)    for(int i=a;i<b;i++)
#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vll vector<ll>
#define vi2d vector<vi>
#define vll2d vector<vll>
#define pb push_back
#define pob pop_back
#define all(v) (v).begin(), (v).end()

//Displaying a vector
template <typename T>
void show(vector<T> arr){
    for(int i=0;i<arr.size();i++){cout<<arr[i]<<" ";}
    cout<<"\n";
}

//Fast exponentiation
template <typename T,typename Y>
ll fpow(T base, Y expo){
    if(expo==0){return 1;}
    else if(expo==1){return base;}
    else{
        if(expo%2==0){return fpow(base,expo/2)*fpow(base,expo/2);}
        else{return base*fpow(base,expo-1);}
    }
}

//******************************************************************************
//Auxiliary Functions go here

//******************************************************************************
void solve(){
    static int coun=0;
    //cout<<"This is a test code "<<coun<<"\n";
    //coun++;
    int n; cin>>n;
    vi p(n); vi c(n);
    int flag = 1;
    rep(i,0,n){
        cin>>p[i]>>c[i];
        if(i){
            if((p[i]<p[i-1])||(c[i]<c[i-1])||(c[i]>p[i])||((p[i]-p[i-1])<(c[i]-c[i-1]))){flag=0;}
        }
        else{
            if(c[i]>p[i]){flag=0;}
        }
    }
    if(flag){cout<<"YES";}
    else{cout<<"NO";}
    cout<<"\n";
}

// main function
int main(){
    IOS
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

    ll t;
    cin>>t;

    while(t--){
        solve();
    }

    return 0;
}
//******************************************************************************


t = int(input())
ans = []
for i in range(t):
    n,s = map(int, input().split())
    a = list(map(int, input().split()))
    b = [0]*(n+1)
    index = 0
    a_max = 0
    flag = True
    for i in range(n):
        b[i+1] = b[i] + a[i]
        a_max = max(a_max,a[i])
        if a[index] != a_max:
            index = i
        if b[i+1] > s:
            flag = False
            break
    if flag:
        ans.append(0)
    else:
        ans.append(index+1)
for i in range(t):
    print(ans[i])


import sys
import math
import itertools
import functools
import collections
import operator

def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def wr(arr): return ' '.join(map(str, arr))
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r
def divs(n, start=1):
    r = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if (n % i == 0):
            if (n / i == i):
                r.append(i)
            else:
                r.extend([i, n // i])
    return r
def divn(n, primes):
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t
def prime(n):
    if n == 2: return True
    if n % 2 == 0 or n <= 1: return False
    sqr = int(math.sqrt(n)) + 1
    for d in range(3, sqr, 2):
        if n % d == 0: return False
    return True
def convn(number, base):
    newnumber = 0
    while number > 0:
        newnumber += number % base
        number //= base
    return newnumber
def cdiv(n, k): return n // k + (n % k != 0)

t = ii()
for _ in range(t):
    n, s = mi()
    a = li()
    if sum(a) <= s:
        print(0)
    else:
        t = 0
        i = 0
        while t < s:
            t += a[i]
            i += 1
        max_ = max(a[:i])
        pos = a[:i].index(max(a[:i]))
        for j in range(i):
            if a[j] == max_:
                pos = j + 1
        print(pos)


import sys
import math
import itertools
import functools
import collections
import operator

def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def wr(arr): return ' '.join(map(str, arr))
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r
def divs(n, start=1):
    r = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if (n % i == 0):
            if (n / i == i):
                r.append(i)
            else:
                r.extend([i, n // i])
    return r
def divn(n, primes):
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t
def prime(n):
    if n == 2: return True
    if n % 2 == 0 or n <= 1: return False
    sqr = int(math.sqrt(n)) + 1
    for d in range(3, sqr, 2):
        if n % d == 0: return False
    return True
def convn(number, base):
    newnumber = 0
    while number > 0:
        newnumber += number % base
        number //= base
    return newnumber
def cdiv(n, k): return n // k + (n % k != 0)

t = ii()
for _ in range(t):
    n, s = mi()
    a = li()
    if sum(a) <= s:
        print(0)
    else:
        max_ = i = t = 0
        while t <= s:
            if a[i] > a[max_]:
                max_ = i
            t += a[i]
            i += 1
        print(max_ + 1)


import sys
import math
import itertools
import functools
import collections
import operator

def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def wr(arr): return ' '.join(map(str, arr))
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r
def divs(n, start=1):
    r = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if (n % i == 0):
            if (n / i == i):
                r.append(i)
            else:
                r.extend([i, n // i])
    return r
def divn(n, primes):
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t
def prime(n):
    if n == 2: return True
    if n % 2 == 0 or n <= 1: return False
    sqr = int(math.sqrt(n)) + 1
    for d in range(3, sqr, 2):
        if n % d == 0: return False
    return True
def convn(number, base):
    newnumber = 0
    while number > 0:
        newnumber += number % base
        number //= base
    return newnumber
def cdiv(n, k): return n // k + (n % k != 0)

t = ii()
for _ in range(t):
    n, s = mi()
    a = li()
    if sum(a) <= s:
        print(0)
    else:
        t = 0
        i = 0
        while t < s:
            t += a[i]
            i += 1
        print(a[:i].index(max(a[:i])) + 1)


import sys
import math
import itertools
import functools
import collections
import operator

def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def wr(arr): return ' '.join(map(str, arr))
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r
def divs(n, start=1):
    r = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if (n % i == 0):
            if (n / i == i):
                r.append(i)
            else:
                r.extend([i, n // i])
    return r
def divn(n, primes):
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t
def prime(n):
    if n == 2: return True
    if n % 2 == 0 or n <= 1: return False
    sqr = int(math.sqrt(n)) + 1
    for d in range(3, sqr, 2):
        if n % d == 0: return False
    return True
def convn(number, base):
    newnumber = 0
    while number > 0:
        newnumber += number % base
        number //= base
    return newnumber
def cdiv(n, k): return n // k + (n % k != 0)

t = ii()
for _ in range(t):
    n, s = mi()
    a = li()
    if sum(a) <= s:
        print(0)
    else:
        t = 0
        i = 0
        while t < s:
            t += a[i]
            i += 1
        max_ = max(a[:i])
        pos = a[:i].index(max(a[:i]))
        for j in range(i):
            if a[i] == max_:
                pos = j + 1
        print(pos)


import math

if __name__== '__main__':
    testCases= int(input())
    for _ in range(testCases):
        n, s= tuple(map(int, input().split()))
        verse= tuple(map(int, input().split()))

        mx= 0
        sm= 0
        for index in range(n):
            mx= max(mx, verse[index])
            sm+= verse[index]
            if sm> s:
                print(verse.index(mx)+1)
                break
        else:
            print(0)


import math

if __name__== '__main__':
    testCases= int(input())
    for _ in range(testCases):
        n, s= [int(x) for x in input().split()]
        verse= [int(x) for x in input().split()]

        say= 0
        for index in range(n):
            say+= verse[index]
            if say> s:
                print(index+ 1)
                break
        else:
            print(0)


import math

if __name__== '__main__':
    testCases= int(input())
    for _ in range(testCases):
        n, s= [int(x) for x in input().split()]
        verse= [int(x) for x in input().split()]

        mx= 0
        sm= 0
        for index in range(n):
            mx= max(mx, verse[index])
            sm+= verse[index]
            if sm> s:
                print(verse.index(mx)+1)
                break
        else:
            print(0)


t = int(input())

for i in range(t):
	n, s = map(int, input().split())
	a = list(map(int, input().split()))
	pref = [a[0]]
	for i in range(1, n):
		pref.append(pref[-1] + a[i])
	if n == 1:
		print(0)
	else:
		res = 0
		total = 0
		m = a[0]
		for i in range(1, n):
			temp = m
			m = max(m, a[i])
			total = pref[i] - m
			if total <= s:
				if m > temp:
					res = i + 1
		if res == 0:
			f = 0
			for i in range(1, n):
				if pref[i] - pref[0] <= s:
					f = 1
					break
			print(f)
		else:
			print(res)


t = int(input())

for i in range(t):
	n, s = map(int, input().split())
	a = list(map(int, input().split()))
	pref = [a[0]]
	for i in range(1, n):
		pref.append(pref[-1] + a[i])
	if n == 1:
		print(0)
	else:
		res = 0
		total = 0
		m = a[0]
		chk = 0
		for i in range(n):
			temp = m
			m = max(m, a[i])
			total = pref[i] - m
			if total <= s:
				chk = 1
				if m > temp:
					res = i + 1
		if chk:
			print(res if res else 1)
		else:
			print(0)


t = int(input())

for i in range(t):
	n, s = map(int, input().split())
	a = list(map(int, input().split()))
	pref = [a[0]]
	for i in range(1, n):
		pref.append(pref[-1] + a[i])
	if pref[-1] <= s:
		print(0)
	else:
		res = 0
		total = 0
		m = a[0]
		for i in range(1, n):
			temp = m
			m = max(m, a[i])
			total = pref[i] - m
			if total <= s:
				if m > temp:
					res = i + 1
		print(res if res else 1)


t = int(input())

for i in range(t):
	n, s = map(int, input().split())
	a = list(map(int, input().split()))
	pref = [a[0]]
	for i in range(1, n):
		pref.append(pref[-1] + a[i])
	if n == 1 or pref[0] > s:
		print(0)
	else:
		res = 0
		total = 0
		m = a[0]
		for i in range(n):
			temp = m
			m = max(m, a[i])
			total = pref[i] - m
			if total <= s:
				if m > temp:
					res = i + 1
		print(res if res else 1)


t = int(input())
while t>=0:
    n,s = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    Sum = 0
    for i in range(0,n):
        Sum+=A[i]
    if Sum <= s:
        print(0)
        continue
    ans =0
    Sum =0
    flag = False

    for i in range(0,n):
        if flag == True:
            break
        if Sum+A[i] > s:
            sec = A[:i]
            #print(sec)
            #print(max(sec),sec.index(max(sec)))
            Sum =Sum - int(max(sec))
            ans = sec.index(max(sec))+1
            flag = True
        Sum += A[i]
    print(ans)
    t= t-1


# your code goes heret = int(input())
try:
	t = int(input())
	while t>=0:
	    n,s = [int(x) for x in input().split()]
	    A = [int(x) for x in input().split()]
	    Sum = 0
	    for i in range(0,n):
	        Sum+=A[i]
	    if Sum <= s:
	        print(0)
	        continue
	    ans =0
	    Sum =0
	    flag = False

	    for i in range(0,n):
	        if flag == True:
	            break
	        if Sum+A[i] > s:
	            sec = A[:i]
	            #print(sec)
	            #print(max(sec),sec.index(max(sec)))
	            Sum =Sum - int(max(sec))
	            ans = sec.index(max(sec))+1
	            flag = True
	        Sum += A[i]
	    print(ans)
	    t= t-1
except:
	pass


try:
    t = int(input())
    while t>0:
        n,s = [int(x) for x in input().split()]
        A = [int(x) for x in input().split()]
        Sum = 0
        for i in range(0,n):
            Sum+=A[i]
        if Sum <= s:
            print(0)
            continue
        ans =0
        Sum =0
        flag = False

        for i in range(0,n):
            if flag == True:
                break
            if Sum+A[i] > s:
                sec = A[:i+1]
                #print(sec)
                #print(max(sec),sec.index(max(sec)))
                Sum =Sum - int(max(sec))
                ans = sec.index(max(sec))+1
                flag = True
            Sum += A[i]
        print(ans)
        t= t-1
except:
    pass


t = int(input())
while t>0:
    n,s = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    Sum = 0
    for i in range(0,n):
        Sum+=A[i]
    if Sum <= s:
        print(0)
        continue
    ans =0
    Sum =0
    flag = False

    for i in range(0,n):
        if flag == True:
            break
        if Sum+A[i] > s:
            sec = A[:i+1]
            #print(sec)
            #print(max(sec),sec.index(max(sec)))
            Sum =Sum - int(max(sec))
            ans = sec.index(max(sec))+1
            flag = True
        Sum += A[i]
    print(ans)
    t= t-1


t = int(input())
while (t):
    t = t-1
    n , s = map(int , input().split())
    arr = list(map(int , input().split()))
    sum = 0
    ans =0
    max = 0
    for i in range (0, len(arr)) :
        sum = sum+ arr[i]
        if (max < arr[i]) :
            max = arr[i]
        if (sum ==s and i == len(arr)-1) :
            ans =0
            break
        elif (sum == s) :
            if (arr[i+1] > arr[i]) :
                ans = i+1+1
            else :
                ans = i+1
            break
        elif (sum > s) :

            ans = arr.index(max) +1
            break
        elif (sum <= s and i==len(arr)-1) :
            ans = 0
            break

    print(ans)


t = int(input())
while (t):
    t = t-1
    n , s = map(int , input().split())
    arr = list(map(int , input().split()))
    sum = 0
    ans =0
    for i in range (0, len(arr)) :
        sum = sum+ arr[i]
        if (sum ==s and i == len(arr)-1) :
            ans =0
            break
        elif (sum == s) :
            if (arr[i+1] > arr[i]) :
                ans = i+1+1
            else :
                ans = i+1
            break
        elif (sum > s) :
            ans = i+1
            break
        elif (sum <= s and i==len(arr)-1) :
            ans = 0
            break

    print(ans)


t = int(input())
while (t):
    t = t-1
    n , s = map(int , input().split())
    arr = list(map(int , input().split()))
    sum = 0
    ans =0
    max = 0
    for i in range (0, len(arr)) :
        sum = sum+ arr[i]
        if (max < arr[i]) :
            max = arr[i]
        if (sum <=s and i == len(arr)-1) :
            ans =0
            break
        elif (sum > s) :
            ans = arr.index(max) +1
            break

    print(ans)


t = int(input())
while (t):
    t = t-1
    n , s = map(int , input().split())
    arr = list(map(int , input().split()))
    sum = 0
    ans =0
    for i in range (0, len(arr)) :
        sum = sum+ arr[i]
        if (sum <=s and i == len(arr)-1) :
            ans =0
            break
        elif (sum == s) :
            if (arr[i+1] > arr[i]) :
                ans = i+1+1

            ans = i+1
            break
        elif (sum > s) :
            ans = i+1
            break

    print(ans)


t = int(input())
while (t):
    t = t-1
    n , s = map(int , input().split())
    arr = list(map(int , input().split()))
    sum = 0
    ans =0
    for i in range (0, len(arr)) :
        sum = sum+ arr[i]
        if (sum <=s and i == len(arr)-1) :
            ans =0
            break
        elif (sum == s) :
            if (arr[i+1] > arr[i]) :
                ans = i+1+1
            else :
                ans = i+1
            break
        elif (sum > s) :
            ans = i+1
            break

    print(ans)


t = int(input())
while (t):
    t = t-1
    n , s = map(int , input().split())
    arr = list(map(int , input().split()))
    sum = 0
    ans =0
    for i in range (0, len(arr)) :
        sum = sum+ arr[i]
        if (sum ==s and i == len(arr)-1) :
            ans =0
            break
        elif (sum == s) :
            if (arr[i+1] > arr[i]) :
                ans = i+1+1

            ans = i+1
            break
        elif (sum > s) :
            ans = i+1
            break

    print(ans)


for _ in range(int(input())):
    n,s = map(int,input().split())
    a = list(map(int,input().split()))

    k = s
    i = 0
    mx = a[0]
    ind = 0
    flag = 0
    if(sum(a) <= s):
        print(0)

    else:
        while(s > 0 and i < n):
            s -= a[i]

            if(a[i] >= mx):
                mx = a[i]
                ind = i
            i += 1

        ans = 0

        if(i < n):
            if(s + mx >= a[i]):
                ans = ind+1

        elif(i==n):
            if(mx > a[i-1]):
                ans = ind + 1

        print(ans)


for _ in range(int(input())):
    n,s = map(int,input().split())
    a = list(map(int,input().split()))

    i = 0
    mx = a[0]
    ind = 0
    flag = 0
    if(sum(a) <= s):
        print(0)

    else:
        while(i < n):

            if(a[i] <= s):
                s = s-a[i]
                if(a[i] >= mx):
                    mx = a[i]
                    ind = i

                mx = max(a[i],mx)

            else:
                if(flag == 0 and s + mx >= a[i]):
                    s = s + mx - a[i]
                    ans = ind
                    flag = 1
                else:
                    break
            i += 1

        if(flag):
            print(ans+1)
        else:
            print(0)


for _ in range(int(input())):
    n,s = map(int,input().split())
    a = list(map(int,input().split()))

    i = 0
    mx = a[0]
    ind = 0
    flag = 0
    while(i < n):

        if(a[i] <= s):
            s = s-a[i]
            if(a[i] >= mx):
                mx = a[i]
                ind = i

            mx = max(a[i],mx)

        else:
            if(flag == 0 and s + mx >= a[i]):
                s = s + mx - a[i]
                ans = ind
                flag = 1
            else:
                break
        i += 1

    if(flag):
        print(ind+1)
    else:
        print(0)


from sys import maxsize
#from collections import Counter as cnt, defaultdict as dic
#import string
#from decimal import Decimal as de
get_int = lambda: int(input())
get_mul_int = lambda: map(int, input().rstrip().split())
get_list = lambda: list(map(int, input().rstrip().split()))

TEST_CASES = True
def main():
    n, s = get_mul_int()
    a = get_list()
    if n==1:
        if s>=a[0]: print(0)
        else: print(1)
        return
    place=0
    for i in range(n):
        if a[i]>a[place]:
            place=i
        s-=a[i]
        if s<0:
            break
    if s>=0:
        print(0)
        return
    else:
        print(place+1)

# START
if not TEST_CASES: main()
else: [main() for _ in range(int(input()))]


from sys import maxsize
#from collections import Counter as cnt, defaultdict as dic
#import string
#from decimal import Decimal as de
get_int = lambda: int(input())
get_mul_int = lambda: map(int, input().rstrip().split())
get_list = lambda: list(map(int, input().rstrip().split()))

TEST_CASES = True
def main():
    n, s = get_mul_int()
    a = get_list()
    m, verse, c, skip = -maxsize, 0, 0, 0
    if n==1:
        if s>a[0]:
            print(0)
        else:
            print(1)
        return

    for i in range(n):
        if verse+a[i]>=s and skip==1:
            break
        elif verse+a[i]>=s:
            skip=1
            c=i
        else:
            verse+=a[i]
    print(c+1)

# START
if not TEST_CASES: main()
else: [main() for _ in range(int(input()))]


t = int(input())
for _ in range(t):
    n = list(map(int, input().split()))
    l = list(map(int, input().split()))
    s = n[1]
    if sum(l)<=s:
        print(0)
    else:

        ma=-1
        ix=-1
        a=0
        for i in range(n[0]):
            if a+l[i]>s:
                if l[i]>ma:
                    ma=l[i]
                    ix= i+1
                break
            else:
                if l[i]>ma:
                    ma=l[i]
                    ix= i+1
                a+=l[i]

        print(ix)


t = int(input())
for _ in range(t):
    n = list(map(int, input().split()))
    l = list(map(int, input().split()))
    s = n[1]
    if sum(l)<=s:
        print(0)
    else:

        ma=-1
        ix=-1
        a=0
        for i in range(n[0]):
            if a+l[i]>s:
                break
            else:
                if l[i]>ma:
                    ma=l[i]
                    ix= i+1
                a+=l[i]

        print(ix)


t = int(input())
for _ in range(t):
    n = list(map(int, input().split()))
    l = list(map(int, input().split()))
    s = n[1]
    if sum(l)<=s:
        print(0)
    else:
        ans=0
        idx=0

        a=0
        for i in range(n[0]):
            if a+l[i]>s:
                break
            else:
                a+=l[i]
                ans+=1
        for i in range(n[0]):
            flag=False
            a=0
            num=0
            for j in range(n[0]):
                if j!=i:
                    if a+l[j]>s:
                        break
                    else:
                        num+=1
                        a+=l[j]
                else:
                    flag=True

            if flag==False:
                break
            elif ans<num:
                ans=num
                idx=i+1
        print(idx)


t=int(input())
l2=[]
for i in range(0,t):
    n, s = map(int, input().split())
    l1=list(map(int,input().strip().split()))[:n]
    l1.sort()
    a=0
    count=0
    for i in l1:
        a=a+i
        if a<=s:
            count=count+1
        else:
            print(0)
    x=len(l1)
    y=x-count
    l2.append(y)
print(*l2, sep = "\n")


t=int(input())
l2=[]
for i in range(0,t):
    n, s = map(int, input().split())
    l1=list(map(int,input().strip().split()))[:n]
    l1.sort()
    a=0
    count=0
    for i in l1:
        a=a+i
        if a<=s:
            count=count+1
        else:
            break;
    x=len(l1)
    y=x-count
    l2.append(y)
print(*l2, sep = "\n")


t=int(input())
l2=[]
for i in range(0,t):
    n, s = map(int, input().split())
    l1=list(map(int,input().split()))
    l1.sort()
    a=0
    count=0
    for j in l1:
        a=a+j
        if a<=s:
            count=1
            break
    if count==1:
        print(l1.index(max(l1[:j+1])+1))
    else:
        print(0)


t=int(input())
n,s=map(int,input().split())
for i in range(0,t):
    l1=list(map(int,input().strip().split()))[:n]
l1.sort()
a=0
count=0
for i in l1:
    a=a+i
    if a<=s:
        count=count+1
    else:
        break;
x=len(l1)
y=x-count
print(y)


t=int(input())
l2=[]
for i in range(0,t):
    n, s = map(int, input().split())
    l1=list(map(int,input().strip().split()))[:n]
    l1.sort()
    a=0
    count=0
    for i in l1:
        a=a+i
        if a<=s:
            count=count+1
    x=len(l1)
    y=x-count
    l2.append(y)
print(*l2, sep = "\n")


t=int(input())
for i in range(0,t):
    n, s = map(int, input().split())
    l1=list(map(int,input().strip().split()))[:n]
l1.sort()
a=0
count=0
for i in l1:
    a=a+i
    if a<=s:
        count=count+1
    else:
        break;
x=len(l1)
y=x-count
print(y)


t=int(input())
l2=[]
for i in range(0,t):
    n, s = map(int, input().split())
    l1=list(map(int,input().split()))
    l1.sort()
    a=0
    count=0
    for j in l1:
        a=a+l1[j]
        if a<=s:
            count=1
            break
    if count==1:
        print(l1.index(max(l1[:j+1])+1))
    else:
        print(0)


t=int(input())
l2=[]
for i in range(0,t):
    n, s = map(int, input().split())
    l1=list(map(int,input().split()))
    a=0
    count=0
    for j in range(n):
        a=a+l1[j]
        if a>=s:
            count=1
            break
    if count==1:
        print(l1.index(max(l1[:j+1]))+1)
    else:
        print(0)


t=int(input())
l2=[]
for i in range(0,t):
    n, s = map(int, input().split())
    l1=list(map(int,input().split()))
    a=0
    count=0
    for j in range(n):
        a=a+l1[j]
        if a>s:
            count=1
            break
    if count==1:
        print(l1.index(max(l1[:j+1]))+1)
    else:
        print(0)


for _ in range(int(input())):
    n,s=map(int,input().split())
    a=list(map(int,input().split()))
    if sum(a)<=s:
        print(0)

    else:
        m=-1
        ans=0
        for i in range(n):
            if a[i]>m:
                m=a[i]
                ans=i
            s-=a[i]
            if s<=0:
                break
        print(ans+1)


for _ in range(int(input())):
    n,s=map(int,input().split())
    a=list(map(int,input().split()))
    if sum(a)<=s:
        print(0)

    else:
        m=-1
        ans=0
        for i in range(n):
            if a[i]>m:
                m=a[i]
                ans=i
            s-=a[i]
            if s<0:
                break
        print(ans+1)


for i in range(int(input())):
    n,s=map(int,input().split())
    a=list(map(int,input().split()))
    al=list(a)
    b=sorted(list(a))
    an=0
    i=n-1
    ss=sum(al)

    while ss>s and i>-1:
        if i==n-1:
            #print(a)
            al.remove(b[i])
            an+=1
        elif a.index(b[i])!=a.index(b[i+1])+1:
            #print(a)
            #print(b)
            al.remove(b[i])
            an+=1
        ss=sum(al)
        i-=1
        #print(al)
        #print(sum(al))
    print(an)


T = int(input())
for i in range(T):
	n,s = map(int, input().split(' '))
	N = [int(x) for x in input().split()]
	N.append(0)
	N.append(0)
	j = 0
	F = False
	G = -1
	R = -1
	X = 0
	while True:
		if s - N[j] > 0 :
			G = max(G,N[j])
			s = s - N[j]
		elif s == N[j] :
			F = True
			G = max(G,N[j])
			break
		else :
			F = False
			R = N[j] - s
			break
		j = j + 1
		if N[j] == 0 :
			X = 1
			break
	if X == 1:
		print("0")
	elif F :
		print(N.index(G)+1)	if G >= N[j+1] + N[j+2] else print("0")
	elif not F :
		G = max(G,N[j])
		print(N.index(G)+1)	if G >= R + N[j+1] else print("0")


T = int(input())
for i in range(T):
	n,s = map(int, input().split(' '))
	N = [int(x) for x in input().split()]
	N.append(0)
	N.append(0)
	j = 0
	F = False
	G = -1
	R = -1
	X = 0
	while True:
		if s - N[j] > 0 :
			G = max(G,N[j])
			s = s - N[j]
		elif s == N[j] :
			F = True
			G = max(G,N[j])
			break
		else :
			F = False
			R = N[j] - s
			break
		j = j + 1
		if N[j] == 0 :
			X = 1
			break
	if X == 1:
		print("0")
	elif F :
		print(N.index(G)+1)	if G >= N[j+1] + N[j+2] else print("0")
	elif not F :
		print(N.index(G)+1)	if G >= R + N[j+1] else print("0")


T = int(input())
for i in range(T):
	n,s = map(int, input().split(' '))
	N = [int(x) for x in input().split()]
	N.append(10000000000)
	N.append(10000000000)
	j = 0
	F = False
	G = -1
	R = -1
	X = 0
	while True:
		if s - N[j] > 0 :
			G = max(G,N[j])
			s = s - N[j]
		elif s == N[j] :
			F = True
			G = max(G,N[j])
			break
		else :
			F = False
			R = N[j] - s
			break
		j = j + 1
		if N[j] == 10000000000 :
			X = 1
			break
	if X == 1:
		print("0")
	elif F :
		print(N.index(G)+1)	if G >= N[j+1] + N[j+2] else print("0")
	elif not F :
		G = max(G,N[j])
		print(N.index(G)+1)	if G >= R + N[j+1] else print("0")


t = int(input())
while t>0:
    n, s = map(int, input().split())
    a = list(map(int, input().split()))
    c = 0
    for i in range(n):
        if a[i] > a[c]:
            c = i
        s -= a[i]
        if s < 0:
            break
    if s >= 0:
        c = -1
    print(c+1)
    t-=1


for _ in range(int(input())):
	n,s = input().split()
	s=int(s)
	n=int(n)
	arr=list()
	arr= list(map(int,input().split()))
	arr.sort()
	sum=0
	flag=False
	for i in range(n):
		if(sum+arr[i] <= s):
			sum+=arr[i]
		else:
			flag=True
			break
	if(flag):
		print(n-i)
	else:
		print(0)


for _ in range(int(input())):
    n,s=map(int,input().split())
    l=list(map(int,input().split()))
    if sum(l)<=s:
        print(0)
    else:
        cur=0
        j=0
        for i in range(n):
            if l[i]>l[j]:
                j=i
            s-=l[i]
            if s<0:
                break

        print(j+1)


for _ in range(int(input())):
    n,s=map(int,input().split())
    l=list(map(int,input().split()))
    if sum(l)<=s:
        print(0)
    else:
        cur=0
        j=0
        for i in range(n):
            if cur+l[i]<=s:
                cur+=l[i]
                j=i
        print(l.index(max(l[:j+2]))+1)


for _ in range(int(input())):
    n,s=map(int,input().split())
    l=list(map(int,input().split()))
    if sum(l)<=s:
        print(0)
    else:
        cur=0
        j=0
        for i in range(n):
            if cur+l[i]<=s:
                cur+=l[i]
                j=i
        print(l.index(max(l[:j+1]))+1)


for _ in range(int(input())):
    n,s=map(int,input().split())
    l=list(map(int,input().split()))
    l1=list()
    i=0; a=0
    while i<len(l) and a+l[i]<=s:
        a+=l[i]
        l1.append(l[i])
        i+=1

    m=max(l1)
    if i>=len(l):print(0)
    elif m<l[i]:
        if len(l1)<len(l):print(len(l1)+1)
        else:print(0)
    else:
        print(l1.index(m)+1)


for _ in range(int(input())):
    n,s=map(int,input().split())
    l=list(map(int,input().split()))
    l1=list()
    i=0; a=0
    if sum(l)<s:print(0);continue
    while i<len(l) and a+l[i]<=s:
        a+=l[i]
        l1.append(l[i])
        i+=1

    m=max(l1)
    if i>=len(l):print(0)
    elif m<l[i]:
        if len(l1)==len(l):print(0)
        else:print(len(l1)+1)
    else:
        print(l1.index(m)+1)


for _ in range(int(input())):
    n,s = map(int,input().split())
    l = list(map(int,input().split()))
    j = 0
    for i in range(n):
        if l[i]>l[j]: j=i
        s -= l[i]
        if s < 0: break

    if s >= 0: j = -1
    print(j+1)


for _ in range(int(input())):
    n,s=map(int,input().split())
    l=list(map(int,input().split()))
    l1=list()
    i=0; a=0
    while i<len(l) and a+l[i]<=s:
        a+=l[i]
        l1.append(l[i])
        i+=1

    m=max(l1)
    if i>=len(l):print(0)
    elif m<l[i]:
        if len(l1)==len(l):print(0)
        else:print(len(l1)+1)
    else:
        print(l1.index(m)+1)


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

    if n == 1 or sum(arr) <= s :
        print('0')

    else:
        sm = 0
        c = 0
        ans = []
        f = 1
        for i in arr:
            if sm + i < s :
                ans.append(i)
                s -= i

            else:
                if f == 1 and sm + i >= s :
                    ans.append(i)
                    f = 0
                    c += 1

                else:
                    break

        #print(ans)
        #print(c)
        print(ans.index(max(ans)) + 1 )


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

    if n == 1 or sum(arr) <= s :
        print('0')

    else:
        sm = 0
        ans = []
        f = True
        for i in arr:
            if i + sm > s :
                ans.append(i)
                f = False
                break

            else:
                sm += i
                ans.append(i)

        if f :
            print('0')

        else:
            print(ans.index(max(ans)) + 1 )


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

    ans = []
    sm = 0
    f = 1
    for i in arr:
        if i + sm > s :
            f = 0
            ans.append(i)
            break

        else:
            sm += i
            ans.append(i)

    if f == 1 :
        print('0')

    else:
        print(ans.index(max(ans)) + 1 )


for _ in range(int(input())):
    a,s = map(int,input().split())
    l = list(map(int,input().split()))
    k=0
    if sum(l)<=s:
        print(0)
    elif l[0]>s:
        if l[min(1,a-1)]>s:
            print(0)
        else:
            print(1)
    else:
        j=l[0]
        s-=j
        x=0
        for i in range(1,a):
            s-=l[i]
            if s<0:
                break
            if l[i]>j:
                j = l[i]
            if s==0:
                break
        if j<l[i] and s+(l[i]-j)<0 :
            print(0)
        else:
            print(l.index(j)+1)


for _ in range(int(input())):
    a,s = map(int,input().split())
    l = list(map(int,input().split()))
    j = 0
    k=-1
    for i in range(a):
        j+=l[i]
        if j>s:
            k=i
            j-=l[i]
            break
    if k==-1:
        print(0)
    else:
        x = max(l[:k+1])
        if j+sum(l[k:k+2])-x<=s:
            print(l.index(x)+1)
        else:
            print(0)


for _ in range(int(input())):
    a,s = map(int,input().split())
    l = list(map(int,input().split()))
    k=0
    if sum(l)<=s:
        print(0)
    elif l[0]>s:
        print(1)
    else:
        j=a-1
        for i in range(a):
            k+=l[i]
            if k>s:
                j = i-1
                break
            if k==s:
                j=i
                break
        print(l.index(max(l[:j+1]))+1)


for _ in range(int(input())):
    a,s = map(int,input().split())
    l = list(map(int,input().split()))
    k=0
    if sum(l)<=s:
        print(0)
    elif l[0]>s:
        if l[1]>s:
            print(0)
        else:
            print(1)
    else:
        j=a-1
        for i in range(a):
            k+=l[i]
            if k>s:
                j = i-1
                break
            if k==s:
                j=i
                break
        print(l.index(max(l[:j+1]))+1)


for _ in range(int(input())):
    a,s = map(int,input().split())
    l = list(map(int,input().split()))
    k=0
    if sum(l)<=s:
        print(0)
    elif l[0]>s:
        if l[min(1,a-1)]>s:
            print(0)
        else:
            print(1)
    else:
        j=l[0]
        s-=j
        x=0
        for i in range(1,a):
            s-=l[i]
            if s<0:
                break
            if l[i]>j:
                j = l[i]
            if s==0:
                break
        if j<l[i+1] and s+(l[i+1]-j)<0 :
            print(0)
        else:
            print(l.index(j)+1)


for _ in range(int(input())):
    a,s = map(int,input().split())
    l = list(map(int,input().split()))
    k=0
    if sum(l)<=s:
        print(0)
    else:
        for i in range(a):
            k+=l[i]
            if k>s:
                j = i-1
                break
            if k==s:
                j=i
                break
        print(l.index(max(l[:j+1]))+1)


for _ in range(int(input())):
    a,s = map(int,input().split())
    l = list(map(int,input().split()))
    k=0
    if sum(l)<=s:
        print(0)
    elif l[0]>s:
        if l[min(1,a)]>s:
            print(0)
        else:
            print(1)
    else:
        j=a-1
        for i in range(a):
            k+=l[i]
            if k>s:
                j = i-1
                break
            if k==s:
                j=i
                break
        print(l.index(max(l[:j+1]))+1)


for _ in range(int(input())):
    a,s = map(int,input().split())
    l = list(map(int,input().split()))
    k=0
    if sum(l)<=s:
        print(0)
    elif l[0]>s:
        if l[min(1,a-1)]>s:
            print(0)
        else:
            print(1)
    else:
        j=a-1
        for i in range(a):
            k+=l[i]
            if k>s:
                j = i-1
                break
            if k==s:
                j=i
                break
        print(l.index(max(l[:j+1]))+1)


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


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


for _ in range (int(input())):
	n, s = map(int, input().split())
	l = list(map(int, input().split()))
	if len(l) == 1:
		if s >= l[0]:
			print(0)
		else:
			print(1)
	else:
		l2 = []
		for i in range (n):
			s -= l[i]
			l2.append(l[i])
			#print(s)
			if s < 0:
				s += l[i]
				i = i - 1
				break
		#print(i, "lllllll", s)
		if i == n - 1:
			print(0)
		else:
			j = i
			m = max(l2)
			for i in range (len(l2)):
				if m == l[i]:
					if s + m > l[j + 1]:
						print(i + 1)
					else:
						print(0)
					break


for _ in range (int(input())):
	n, b = map(int, input().split())
	l = list(map(int, input().split()))
	f = True
	if len(l) == 1:
		if b >= l[0]:
			print("0")
		else:
			print("1")
	else:
		i = 0
		while (i < n - 1):
			j = i
			while (l[j + 1] > l[j]):
				j += 1
				print(j + 1)
				f = False
			if f == False:
				break
			i += 1
		if f == True:
			print("0")


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


t = int(input())
for _ in range(t):
    n, time = map(int, input().split())
    mas = list(map(int, input().split()))
    c = 0
    maso = []
    for i in range(n):
        time -= mas[i]
        if time >= 0:
            maso.append(mas[i])
        else:
            break
    if time < 0:
        print(1 + mas.index(max(maso)))
    else:
        print(0)


t = int(input())
for _ in range(t):
    n, t = map(int, input().split())
    mas = list(map(int, input().split()))
    b = t
    c = 0
    maso = []
    time = t
    for i in range(n):
        time -= mas[i]
        if time >= 0:
            maso.append(mas[c])
        c += 1
    if time < 0:
        print(mas.index(max(maso)) + 1)
    else:
        print(0)


t = int(input())
for _ in range(t):
    n, t = map(int, input().split())
    mas = list(map(int, input().split()))
    b = t
    c = 0
    maso = []
    time = t
    for i in range(n):
        time -= mas[i]
        if time >= 0:
            maso.append(mas[i])
    if time < 0:
        print(mas.index(max(maso)) + 1)
    else:
        print(0)


t = int(input())
for _ in range(t):
    n, t = map(int, input().split())
    mas = list(map(int, input().split()))
    b = t
    c = 0
    maso = []
    time = t
    while c != n :
        count = 0
        time = t
        for i in range(len(mas)):
            if i == 0:
                if time - mas[i] >= 0:
                    time -= mas[i]
                    count += 1

            elif i != c:
                if time - mas[i] >= 0:
                    time -= mas[i]
                    count += 1
            if time - mas[i] < 0:
                break
        l = []
        l.append(count)
        l.append(c)
        c += 1
        maso.append(l)

    n_min = 0
    for i in range(len(maso)):
        if maso[i][0] > maso[n_min][0]:
            n_min = i
    if maso[n_min][1] + 1 !=n:
        print(maso[n_min][1] + 1)
    else:
        print(0)


t = int(input())
for _ in range(t):
    n, t = map(int, input().split())
    mas = list(map(int, input().split()))
    b = t
    c = 0
    maso = []
    time = t
    while c != n:
        time -= mas[c]
        if time >=0:
            maso.append(mas[c])
        c += 1
    if time <0:
        print(mas.index(max(maso)) + 1)
    else:
        print(0)


t = int(input())
for _ in range(t):
    n, t = map(int, input().split())
    mas = list(map(int, input().split()))
    b = t
    c = 0
    maso = []
    time = t
    for i in range(n):
        time -= mas[i]
        if time >= 0:
            maso.append(mas[i])
        else:
            break
    if time < 0:
        print(1 + mas.index(max(maso)))
    else:
        print(0)


t = int(input())
for _ in range(t):
    n, t = map(int, input().split())
    mas = list(map(int, input().split()))
    b = t
    c = 0
    maso = []
    time = t
    while c != n + 1:
        count = 0
        time = t
        for i in range(len(mas)):
            if i == 0:
                if time - mas[i] >= 0:
                    time -= mas[i]
                    count += 1

            elif i != c:
                if time - mas[i] >= 0:
                    time -= mas[i]
                    count += 1
            if time - mas[i] < 0:
                break
        l = []
        l.append(count)
        l.append(c)
        c += 1
        maso.append(l)
    if n != 1:
        n_min = 0
        for i in range(len(maso)):
            if maso[i][0] > maso[n_min][0]:
                n_min = i
        print(maso[n_min][1] + 1)
    else:
        print(0)


t = int(input())
for _ in range(t):
    n, t = map(int, input().split())
    mas = list(map(int, input().split()))
    b = t
    c = 0
    maso = []
    while c != n - 1:
        count = 0
        t = b
        for i in range(c, len(mas)):
            if t - mas[i] >= 0:
                t -= mas[i]
                count += 1

        l = []
        l.append(count)
        l.append(c)
        maso.append(l)
        c += 1

    if n != 1:
        n_min = 0
        for i in range(len(maso)):
            if maso[i][0] > maso[n_min][0]:
                n_min = i
        print(maso[n_min][1])
    else:
        print(0)


t = int(input())
for _ in range(t):
    n, t = map(int, input().split())
    mas = list(map(int, input().split()))
    b = t
    c = 0
    maso = []
    time = t
    while c != n - 1:
        time -= mas[c]
        if time >=0:
            maso.append(mas[c])
        c += 1
    if time <0:
        print(mas.index(max(maso)) + 1)
    else:
        print(0)


t = int(input())
for _ in range(t):
    n, time = map(int, input().split())
    mas = list(map(int, input().split()))
    c = 0
    maso = []
    for i in range(n):
        time -= mas[i]
        maso.append(mas[i])
        if time >= 0:
            continue
        else:
            break
    if time < 0:
        print(1 + mas.index(max(maso)))
    else:
        print(0)


t=int(input())
for i in range(t):
    n, s=map(int, input().split())
    l=list(input().split())
    l=[int(x) for x in l]
    sum=0
    m=l[0]
    mn=0
    flag=0
    for j in range(1,n):
        #print(j)
        if m<=l[j]:
            if sum+m<=s:
                sum = sum + m
                m = l[j]
                mn = j

            else:
                print(mn+1)
                flag=1
                break

        else:
            if sum+l[j]<=s:
                sum+=l[j]
            else:
                print(mn+1)
                flag=1
                break

    if flag==0:
        print('0')


t=int(input())
for i in range(t):
    n, s=map(int, input().split())
    l=list(input().split())
    l=[int(x) for x in l]
    sum=0
    m=l[0]
    mn=0
    flag=0
    for j in range(1,n):
        #print(j)
        if m<=l[j]:
            if sum+m<=s:
                sum = sum + m
                m = l[j]
                mn = j
            else:
                print(mn+1)
                flag=1
                break

        else:
            if sum+l[j]<=s:
                sum+=l[j]
            else:
                print(mn+1)
                flag=1
                break

    if flag==0:
        if mn!=n-1:
            if sum +m >s:
                print(mn+1)
            else:
                print('0')
        else:
            print('0')


t=int(input())
for i in range(t):
    n, s=map(int, input().split())
    l=list(map(int,input().split()))
    sum=0
    m=l[0]
    mn=0
    flag=0
    for j in range(n):
        if m<l[j]:
            if sum+m<=s:
                m = l[j]
                mn = j
                sum = sum + m
            else:
                print(mn+1)
                flag=1
                break

        else:
            if sum+l[j]<=s:
                sum+=l[j]
            else:
                print(mn+1)
                flag=1
                break
    if flag==0:
        print('0')


t=int(input())
for i in range(t):
    n, s=map(int, input().split())
    l=list(map(int,input().split()))
    sum=0
    m=l[0]
    mn=0
    flag=0
    for j in range(n):
        if m<l[j]:
            if sum+m<=s:
                m = l[j]
                mn = j
                sum = sum + m
            else:
                print(mn+1)
                flag=1
                break

        else:
            if sum+l[j]<=s:
                sum+=l[j]
            else:
                print(mn+1)
                flag=1
                break
        if j==n-1 and n>1:
            if sum+l[j]>s:
                print(j+1)
                flag=1
    if flag==0:
        print('0')


t=int(input())
for i in range(t):
    n, s=map(int, input().split())
    l=list(input().split())
    l=[int(x) for x in l]
    sum=0
    m=l[0]
    mn=0
    flag=0
    for j in range(1,n):
        #print(j)
        if m<=l[j]:
            if sum+m<=s:
                sum = sum + m
                m = l[j]
                mn = j
            else:
                print(mn+1)
                flag=1
                break

        else:
            if sum+l[j]<=s:
                sum+=l[j]
            else:
                print(mn+1)
                flag=1
                break

    if flag==0:
        if mn!=n-1:
            if sum +m >s:
                print(mn+1)
        else:
            print('0')


t=int(input())
for i in range(t):
    n, s=map(int, input().split())
    l=list(map(int,input().split()))
    sum=0
    m=l[0]
    mn=0
    flag=0
    for j in range(n):
        if m<l[j]:
            if sum+m<=s:
                m = l[j]
                mn = j
                sum = sum + m
            else:
                print(mn+1)
                flag=1
                break

        else:
            if sum+l[j]<=s:
                sum+=l[j]
            else:
                print(mn+1)
                flag=1
                break
        if j==n-1:
            if sum+l[j]>s:
                print(j+1)
                flag=1
    if flag==0:
        print('0')


for _ in range(int(input())):
    p,q=map(int,input().split());sum=0;flg=0
    A=list(map(int,input().split()));m=0
    for i in range(p):
        if A[i]>q:
            print(i+1)
            flg=1
            break
        else:
            sum+=A[i]
            m=max(m, A[i])
        if sum>q:
            print(A.index(m)+1)
            flg=1
            break
    if flg==0:
        print(0)


for _ in range(int(input())):
    p,q=map(int,input().split());sum=0;flg=0
    A=list(map(int,input().split()));m=0
    for i in range(p):
        if A[i]>=q:
            print(i+1)
            flg=1
            break
        else:
            sum+=A[i]
            m=max(m, A[i])
        if sum>q:
            print(A.index(m)+1)
            flg=1
    if flg==0:
        print(0)


t=int(input())
for i in range(t):
    n,s=input().strip().split(" ")
    n,s=[int(n),int(s)]
    x=list(map(int,input().strip().split(" ")))
    maxa=x[0]
    ii=0
    suma=0
    for i in range(n):
        if suma+x[i]<=s:
            suma+=x[i]
            if x[i+1]>maxa:
                ii=i+2
                maxa=x[i+1]
        elif suma>s:
            break

    if suma==sum(x):
        print(0)
    elif maxa==0:
        print(1)
    else:
        print(ii)


t=int(input())
for i in range(t):
    n,s=input().strip().split(" ")
    n,s=[int(n),int(s)]
    x=list(map(int,input().strip().split(" ")))
    maxa=x[0]
    ii=0
    suma=0
    for i in range(n):
        if suma+x[i]<=s:
            suma+=x[i]
            if i<n-1 and x[i+1]>=maxa:
                ii=i+2
                maxa=x[i+1]
        elif suma>s:
            break

    if suma==sum(x) or sum(x)<=s:
        print(0)
    elif maxa==0 or maxa ==x[0]:
        print(1)

    else:
        print(ii)


t=int(input())
for i in range(t):
    n,s=input().strip().split(" ")
    n,s=[int(n),int(s)]
    x=list(map(int,input().strip().split(" ")))
    maxa=x[0]
    ii=0
    suma=0
    for i in range(n):
        if suma+x[i]<=s:
            suma+=x[i]
            if i<n-1 and x[i+1]>=maxa:
                ii=i+2
                maxa=x[i+1]
        elif suma+x[i]>s:
            break

    if suma==sum(x) or sum(x)<=s:
        print(0)
    elif maxa==0 or maxa ==x[0]:
        print(1)

    else:
        print(ii)


t=int(input())
for i in range(t):
    n,s=input().strip().split(" ")
    n,s=[int(n),int(s)]
    x=list(map(int,input().strip().split(" ")))
    maxa=x[0]
    ii=0
    suma=0
    for i in range(n):
        if suma+x[i]<=s:
            suma+=x[i]
            if i<n-1 and x[i+1]>=maxa:
                ii=i+2
                maxa=x[i+1]
        elif suma>s:
            break

    if suma==sum(x):
        print(0)
    elif maxa==0 or maxa ==x[0]:
        print(1)

    else:
        print(ii)


t=int(input())
for i in range(t):
    n,s=input().strip().split(" ")
    n,s=[int(n),int(s)]
    x=list(map(int,input().strip().split(" ")))
    maxa=x[0]
    ii=0
    suma=0
    for i in range(n):
        if suma+x[i]<=s:
            suma+=x[i]
            if i<n-1 and x[i+1]>=maxa:
                ii=i+2
                maxa=x[i+1]
        elif suma>s:
            break

    if suma==sum(x) or suma<s:
        print(0)
    elif maxa==0 or maxa ==x[0]:
        print(1)

    else:
        print(ii)


t=int(input())
for i in range(t):
    n,s=input().strip().split(" ")
    n,s=[int(n),int(s)]
    x=list(map(int,input().strip().split(" ")))
    x1=[]
    for i in range(n):
        x1.append([x[i],i])
    x1.sort()
    suma=0
    for i in range(n):
        if suma+x1[i][0]<=s:
            suma+=x1[i][0]
        elif suma+x1[i][0]>s:
            f=x1[i][1]

            break
    if suma==sum(x):
        print(0)
    else:
        print(f+1)


t=int(input())
for i in range(t):
    n,s=input().strip().split(" ")
    n,s=[int(n),int(s)]
    x=list(map(int,input().strip().split(" ")))
    maxa=0
    ii=0
    suma=0
    for i in range(n):
        if suma+x[i]<=s:
            suma+=x[i]
            if x[i]>maxa:
                ii=i+1
                maxa=x[i]
        elif suma>s:
            break

    if suma==sum(x):
        print(0)
    elif maxa==0:
        print(1)
    else:
        print(ii)


for _ in range(int(input())):
    n,s=map(int,input().split())
    l=list(map(int,input().split()))
    t=0
    maz=0
    count=0
    for i in range(0,n):
        t=t+l[i]
        if l[maz]<l[i]:
            maz=i
        if t>s:
            count+=1
            t=t-l[maz]
    print(count)


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


for _ in range(int(input())):
    n,s=map(int,input().split())
    l=list(map(int,input().split()))
    t=0
    maz=-1
    count=0
    for i in range(0,n):
        t=t+l[i]
        if maz==-1:
            maz=0
        elif l[i]>l[maz] and maz!=-1:
            maz=i
        if t>s:
            count+=1
            t=t-l[maz]
    print(count)


for i in range(int(input())):
    n, s = map(int, input().split())
    arr = list(map(int, input().split()))
    ok, dem, check,  = sum(arr), 0,  0
    for j in range(len(arr)-1):
        dem += arr[j]
        if dem+arr[j+1] > s:
            dem -= max(arr[:j])
            if j < len(arr)-1 and dem + arr[j+1] <= s:
                print(arr[:j+1].index(max(arr[:j+1]))+1)
                check = 1
                break
            if j == len(arr)-1:
                if dem - max(arr) <= s:
                    print(arr.index(max(arr)) + 1)
                    check = 1
                    break
    if check == 0:
        print(0)


for i in range(int(input())):
    n, s = map(int, input().split())
    arr = list(map(int, input().split()))
    ok, dem, check,  = sum(arr), 0,  0
    for j in range(len(arr)):
        dem += arr[j]
        if dem > s:
            dem -= max(arr[:j+1])
            if j < len(arr)-1 and dem + arr[j+1] <= s:
                print(arr[:j+1].index(max(arr[:j+1]))+1)
                check = 1
                break
            if j == len(arr)-1:
                if dem - max(arr) <= s:
                    print(arr.index(max(arr)) + 1)
                    check = 1
                    break

    if check == 0:
        print(0)


import java.io.*;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.*;

public class Solu {
    static StringBuffer str = new StringBuffer();
    static InputReader in = new InputReader(System.in);
    static int mm=1000000007;
    public static void main(String[] args) {
        int i,j,it,t;
        int n=in.nextInt();
        long a[]=new long[n];
        long hk=0;
        long kj=0;
        for(i=0;i<n;i++){
            a[i]=in.nextLong();
            hk+=a[i];
        }
        int k=in.nextInt();
        long b[]=new long[k];

        for(i=0;i<k;i++){
            b[i]=in.nextLong();
            kj+=b[i];
        }
        long ss1=a[0];
        long ss2=b[0];
        int x=1;
        int y=1;
        ArrayList<Long> z=new ArrayList<>();
        ArrayList<Long> w=new ArrayList<>();
        while(true){
            if(ss1==ss2 &&ss1!=0){
                z.add(ss1);
                w.add(ss2);
                ss1=ss2=0;
            }
            else{
                if(ss1>ss2){
                    ss2+=b[y];
                    y+=1;
                }else{
                    ss1+=a[x];
		x+=1;
                }
            }
            if(x>=n || y>=k)
                break;
        }
        if(x<n){
            long kl=0;
            for(i=x;i<n;i++){
                kl+=a[i];
            }
            ss1+=kl;
        }
        if(y<k){
            long kl=0;
            for(i=y;i<k;i++){
                kl+=b[i];
            }
            ss2+=kl;
        }
        if(ss1==ss2 &&ss1!=0){
                z.add(ss1);
                w.add(ss2);
                ss1=ss2=0;
            }
        long gg=0;
        long hh=0;
        for(i=0;i<z.size();i++){
            gg+=z.get(i);
        }
        for(i=0;i<w.size();i++){
            hh+=w.get(i);
        }
        if(gg!=hh|| z.size()!=w.size()  || gg!=hk || hh!=kj){
            System.out.println(-1);
        }else{
            boolean fl=true;
            for(i=0;i<z.size();i++){
                if(z.get(i)!=w.get(i)){
                    fl=false;
                    break;
                }
            }
            if(fl)
            System.out.println(z.size());
            else
                System.out.println(-1);
        }
    }
    static long gcd(long a, long b){
        return (b==0)?a:gcd(b,a%b);
    }
    static int gcdi(int a, int b){
        return (b==0)?a:gcdi(b,a%b);
    }
    public static void ap(String st){
        str.append(st);
    }
    public static void pn() {
        System.out.println(str);
    }
    static class InputReader {

        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new UnknownError();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new UnknownError();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int peek() {
            if (numChars == -1) {
                return -1;
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    return -1;
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar];
        }

        public void skip(int x) {
            while (x-- > 0) {
                read();
            }
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public String nextString() {
            return next();
        }

        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuffer res = new StringBuffer();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));

            return res.toString();
        }

        public String nextLine() {
            StringBuffer buf = new StringBuffer();
            int c = read();
            while (c != '\n' && c != -1) {
                if (c != '\r') {
                    buf.appendCodePoint(c);
                }
                c = read();
            }
            return buf.toString();
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E') {
                    return res * Math.pow(10, nextInt());
                }
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E') {
                        return res * Math.pow(10, nextInt());
                    }
                    if (c < '0' || c > '9') {
                        throw new InputMismatchException();
                    }
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public boolean hasNext() {
            int value;
            while (isSpaceChar(value = peek()) && value != -1) {
                read();
            }
            return value != -1;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    }
}