#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

//defines
typedef long long ll;

using namespace std;

void func(int par, vector<int> &arr, int n){
    if(arr[par] == 0 || n <= 2*par ){ arr[par]=0; return ; }
    int l = 2*par, r = 2*par+1;

    if(arr[l] < arr[r]){
        arr[par] = arr[r]; func(r, arr, n);
    }
    else{ arr[par] = arr[l]; func(l, arr, n); }
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t; cin>>t;
    while(t--){
        ll h,g; cin>>h>>g;
        int n = pow(2,h) , nn = pow(2,g);
        vector<int> arr(n);
        for(int i=1; i<n; i++) cin>>arr[i];

        int d = n - nn;

        vector<int> ans(d); int xx=0;
        int cur,ind;
        for(int i=h-1; i>=g; i--){
            cur = pow(2, i-1)-1;
            for(int j=pow(2,i)-1; j>cur; j--){
                func(j, arr, n); ans[xx++]=j;   //cout<<j<<" ";
            }
            ind=pow(2,i)-1;
            while(ind!=1){
                if( arr[ind-1] < arr[ind] ){
                    func(ind-1, arr, n);  ans[xx++]=ind-1;  //cout<<ind-1<<" ";
                }
                else{
                    func(ind, arr, n);  ans[xx++]=ind;  //cout<<ind<<" ";
                }
                ind-=2;
            }
            ans[xx++]=1; func(1, arr, n); //cout<<1<<" ";
        }

        ll sum=0;
        for(int i=1; i<nn; i++) sum+=arr[i];
        for(int i=1; i<nn; i++) cout<<arr[i]<<" "; cout<<endl;
        cout<<sum<<endl;
        for(int i=0; i<d; i++) cout<<ans[i]<<" "; cout<<endl;
    }
}


//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Rd(a) (a=read())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int read(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	c^'-'?(k=1,x=c&15):k=x=0;
	while(isdigit(Gc(c)))x=(x<<1)+(x<<3)+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define N (4000010)
int t,g,h,a[N],s,d[N];
void dfs(int u);
vector<int>ac;
void opt(int u);
signed main(){
	Rd(t);
	Frn0(i,1,1<<20)d[i]=d[i>>1]+1;
	while(t--){
		Rd(h),Rd(g),ac.clear(),s=0;
		Frn0(i,1,1<<h)Rd(a[i]);
		dfs(1);
		Frn0(i,1,1<<g)s+=a[i];
		wr(s),Pe;
		for(int i:ac)wr(i),Ps;Pe;
	}
	exit(0);
}
void dfs(int u){
	if(!a[u])return;
	while(a[u]){
		int v(u);
		while(a[v])v=a[v<<1]>a[v<<1|1]?v<<1:v<<1|1;
		if(d[v]-1>g)opt(u);
		else break;
	}
	dfs(u<<1),dfs(u<<1|1);
}
void opt(int u){
	ac.push_back(u);
	while(1){
		int ls(u<<1),rs(u<<1|1);
		if(!a[ls]&&!a[rs]){a[u]=0;break;}
		if(a[ls]>a[rs])a[u]=a[ls],u=ls;
		else a[u]=a[rs],u=rs;
	}
}


//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Rd(a) (a=read())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int read(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	c^'-'?(k=1,x=c&15):k=x=0;
	while(isdigit(Gc(c)))x=(x<<1)+(x<<3)+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define N (4000010)
#define Ls(u) ((u)<<1)
#define Rs(u) (Ls(u)|1)
int t,g,h,a[N],s,d[N];
void dfs(int u);
vector<int>ac;
void opt(int u);
signed main(){
	Rd(t);
	Frn0(i,1,1<<21)d[i]=d[i>>1]+1;
	while(t--){
		Rd(h),Rd(g),ac.clear(),s=0;
		Frn0(i,1,1<<h)Rd(a[i]);
		Frn0(i,1<<h,1<<(h+1))a[i]=0;
		dfs(1);
		Frn0(i,1,1<<g)s+=a[i];
		wr(s),Pe;
		for(int i:ac)wr(i),Ps;Pe;
	}
	exit(0);
}
void dfs(int u){
	if(!a[u])return;
	while(a[u]){
		int v(u);
		while(a[v])v=a[Ls(v)]>a[Rs(v)]?Ls(v):Rs(v);
		if(d[v>>1]>g)opt(u);
		else break;
	}
	dfs(u<<1),dfs(u<<1|1);
}
void opt(int u){
	ac.push_back(u);
	while(1){
		if(!a[Ls(u)]&&!a[Rs(u)]){a[u]=0;return;}
		if(a[Ls(u)]>a[Rs(u)])a[u]=a[Ls(u)],u=Ls(u);
		else a[u]=a[Rs(u)],u=Rs(u);
	}
}


//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define Rd(a) (a=read())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int read(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	c^'-'?(k=1,x=c&15):k=x=0;
	while(isdigit(Gc(c)))x=(x<<1)+(x<<3)+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define N (4000010)
int t,g,h,a[N],s;
void dfs(int u,int d);
vector<int>ac;
void opt(int u);
signed main(){
	Rd(t);
	while(t--){
		Rd(h),Rd(g),ac.clear(),s=0;
		Frn0(i,1,1<<h)Rd(a[i]);
		dfs(1,1);
		Frn0(i,1,1<<g)s+=a[i];
		wr(s),Pe;
		for(int i:ac)wr(i),Ps;Pe;
	}
	exit(0);
}
void dfs(int u,int d){
	if(!a[u])return;
	while(1){
		int dt(-1);
		for(int v(u);a[v];++dt,v=a[v<<1]>a[v<<1|1]?v<<1:v<<1|1);
		if(d+dt>g)opt(u);
		else break;
	}
	dfs(u<<1,d+1),dfs(u<<1|1,d+1);
}
void opt(int u){
	ac.push_back(u);
	while(1){
		int ls(u<<1),rs(u<<1|1);
		if(!a[ls]&&!a[rs]){a[u]=0;break;}
		if(a[ls]>a[rs])a[u]=a[ls],u=ls;
		else a[u]=a[rs],u=rs;
	}
}


//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Rd(a) (a=read())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int read(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	c^'-'?(k=1,x=c&15):k=x=0;
	while(isdigit(Gc(c)))x=(x<<1)+(x<<3)+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define N (4000010)
#define Ls(u) ((u)<<1)
#define Rs(u) (Ls(u)|1)
int t,g,h,a[N],s,d[N];
void dfs(int u);
vector<int>ac;
void opt(int u);
signed main(){
	Rd(t);
	Frn0(i,1,1<<20)d[i]=d[i>>1]+1;
	while(t--){
		Rd(h),Rd(g),ac.clear(),s=0;
		Frn0(i,1,1<<h)Rd(a[i]);
		dfs(1);
		Frn0(i,1,1<<g)s+=a[i];
		wr(s),Pe;
		for(int i:ac)wr(i),Ps;Pe;
	}
	exit(0);
}
void dfs(int u){
	if(!a[u])return;
	while(a[u]){
		int v(u);
		while(a[v])v=a[Ls(v)]>a[Rs(v)]?Ls(v):Rs(v);
		if(d[v>>1]>g)opt(u);
		else break;
	}
	dfs(u<<1),dfs(u<<1|1);
}
void opt(int u){
	ac.push_back(u);
	while(1){
		if(!a[Ls(u)]&&!a[Rs(u)]){a[u]=0;return;}
		if(a[Ls(u)]>a[Rs(u)])a[u]=a[Ls(u)],u=Ls(u);
		else a[u]=a[Rs(u)],u=Rs(u);
	}
}


//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Rd(a) (a=read())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int read(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	c^'-'?(k=1,x=c&15):k=x=0;
	while(isdigit(Gc(c)))x=(x<<1)+(x<<3)+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define N (4000010)
#define Ls(u) ((u)<<1)
#define Rs(u) (Ls(u)|1)
int t,g,h,a[N],s,d[N];
void dfs(int u);
vector<int>ac;
void opt(int u);
signed main(){
	Rd(t);
	Frn0(i,1,1<<20)d[i]=d[i>>1]+1;
	while(t--){
		Rd(h),Rd(g),ac.clear(),s=0,Mst(a,0);
		Frn0(i,1,1<<h)Rd(a[i]);
		dfs(1);
		Frn0(i,1,1<<g)s+=a[i];
		wr(s),Pe;
		for(int i:ac)wr(i),Ps;Pe;
	}
	exit(0);
}
void dfs(int u){
	if(!a[u])return;
	while(a[u]){
		int v(u);
		while(a[v])v=a[Ls(v)]>a[Rs(v)]?Ls(v):Rs(v);
		if(d[v>>1]>g)opt(u);
		else break;
	}
	dfs(u<<1),dfs(u<<1|1);
}
void opt(int u){
	ac.push_back(u);
	while(1){
		if(!a[Ls(u)]&&!a[Rs(u)]){a[u]=0;return;}
		if(a[Ls(u)]>a[Rs(u)])a[u]=a[Ls(u)],u=Ls(u);
		else a[u]=a[Rs(u)],u=Rs(u);
	}
}


//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Rd(a) (a=read())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int read(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	c^'-'?(k=1,x=c&15):k=x=0;
	while(isdigit(Gc(c)))x=(x<<1)+(x<<3)+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define N (4000010)
int t,g,h,a[N],s;
void dfs(int u,int d);
vector<int>ac;
void opt(int u);
signed main(){
	Rd(t);
	while(t--){
		Rd(h),Rd(g),ac.clear(),s=0;
		Frn0(i,1,1<<h)Rd(a[i]);
		dfs(1,1);
		Frn0(i,1,1<<g)s+=a[i];
		wr(s),Pe;
		for(int i:ac)wr(i),Ps;Pe;
	}
	exit(0);
}
void dfs(int u,int d){
	if(!a[u])return;
	while(1){
		int dt(-1);
		for(int v(u);a[v];++dt,v=a[v<<1]>a[v<<1|1]?v<<1:v<<1|1);
		if(d+dt>g)opt(u);
		else break;
	}
	dfs(u<<1,d+1),dfs(u<<1|1,d+1);
}
void opt(int u){
	ac.push_back(u);
	while(1){
		int ls(u<<1),rs(u<<1|1);
		if(!a[ls]&&!a[rs]){a[u]=0;break;}
		if(a[ls]>a[rs])a[u]=a[ls],u=ls;
		else a[u]=a[rs],u=rs;
	}
}


//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define Rd(a) (a=read())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int read(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	c^'-'?(k=1,x=c&15):k=x=0;
	while(isdigit(Gc(c)))x=(x<<1)+(x<<3)+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define N (2000010)
int t,g,h,a[N],s;
void dfs(int u,int d);
vector<int>ac;
void opt(int u);
signed main(){
	Rd(t);
	while(t--){
		Rd(h),Rd(g),ac.clear(),s=0;
		Frn0(i,1,1<<h)Rd(a[i]);
		dfs(1,1);
		Frn0(i,1,1<<g)s+=a[i];
		wr(s),Pe;
		for(int i:ac)wr(i),Ps;Pe;
	}
	exit(0);
}
void dfs(int u,int d){
	if(!a[u])return;
	while(1){
		int dt(-1);
		for(int v(u);a[v];++dt,v=a[v<<1]>a[v<<1|1]?v<<1:v<<1|1);
		if(d+dt>g)opt(u);
		else break;
	}
	dfs(u<<1,d+1),dfs(u<<1|1,d+1);
}
void opt(int u){
	ac.push_back(u);
	while(1){
		int ls(u<<1),rs(u<<1|1);
		if(!a[ls]&&!a[rs]){a[u]=0;break;}
		if(a[ls]>a[rs])a[u]=a[ls],u=ls;
		else a[u]=a[rs],u=rs;
	}
}


//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Rd(a) (a=read())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int read(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	c^'-'?(k=1,x=c&15):k=x=0;
	while(isdigit(Gc(c)))x=(x<<1)+(x<<3)+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
#define N (4000010)
int t,g,h,a[N],s;
void dfs(int u,int d);
vector<int>ac;
void opt(int u);
signed main(){
	Rd(t);
	while(t--){
		Rd(h),Rd(g),ac.clear(),s=0;
		Frn0(i,1,1<<h)Rd(a[i]);
		dfs(1,1);
		Frn0(i,1,1<<g)s+=a[i];
		wr(s),Pe;
		for(int i:ac)wr(i),Ps;Pe;
	}
	exit(0);
}
void dfs(int u,int d){
	if(!a[u])return;
	while(a[u]){
		int dt(-1);
		for(int v(u);a[v];++dt,v=a[v<<1]>a[v<<1|1]?v<<1:v<<1|1);
		if(d+dt>g)opt(u);
		else break;
	}
	dfs(u<<1,d+1),dfs(u<<1|1,d+1);
}
void opt(int u){
	ac.push_back(u);
	while(1){
		int ls(u<<1),rs(u<<1|1);
		if(!a[ls]&&!a[rs]){a[u]=0;break;}
		if(a[ls]>a[rs])a[u]=a[ls],u=ls;
		else a[u]=a[rs],u=rs;
	}
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = (1 << 20) + 5;

int t, h, g, n, m;

int a[N], dep[N];

struct node {
	int v, i;

	bool operator < (const node &a) const {
		if (v != a.v) return v > a.v;
		return i < a.i;
	}
};

multiset <node> s;

vector <int> ans;

ll sum;

void add(int idx) {s.insert((node){a[idx], idx});}

void del(int idx) {
	auto it = s.find((node){a[idx], idx});
	if (it != s.end()) s.erase(it);
}

int work(int idx, int test = false) {
	while (1) {
		if (!test) del(idx);
		int ls = idx << 1, rs = ls | 1;
		if ((ls >= n || a[ls] == 0) && (rs >= n || a[rs] == 0)) {
			if (!test) return a[idx] = 0;
			else       return dep[idx] != g;
		}
		if (a[ls] > a[rs]) {
			if (!test) a[idx] = a[ls], add(idx);
			idx = ls;
		}
		else {
			if (!test) a[idx] = a[rs], add(idx);
			idx = rs;
		}
	}
}

void print() {
	for (int i = 1; i < n; i ++) cerr << a[i] << ' ';
		cerr << endl;
		for (auto i : s) cerr << i.v << ' ' << i.i << endl;
		cerr << endl;
	cerr << endl;
}

int main() {
	ios::sync_with_stdio(false);
	dep[1] = 1;
	for (int i = 2; i < N; i ++) dep[i] = dep[i >> 1] + 1;
	for (cin >> t; t --; ) {
		s.clear(), ans.clear();
		cin >> h >> g; n = 1 << h; m = 1 << g;
		for (int i = 1; i < n; i ++) cin >> a[i], add(i);
		for (int idx, i = m; i < n; i ++) {
			//int cnt = 0;
			for (idx = (*s.begin()).i; ; ) {
				cerr << idx << endl;
				del(idx);
				if (work(idx, true)) break;
				idx = (*s.begin()).i;
				//if (++cnt > 10) exit(0);
			}
			cerr << "idx = " << idx << endl;
			ans.push_back(idx); work(idx);
			//print();
		}
		sum = 0;
		for (int i = 1; i < m; i ++) sum += a[i];
		cout << sum << '\n';
		for (int i : ans) cout << i << ' ';
		cout << '\n';
	}
	return 0;
}


#include <iostream>
using namespace std;
int p,m,a,q,n,k=1;
int ar[1000001];
main (){
    cin>>n;
    for (int i=1;i<=n;i++){

      cin>>a;
      for(int j=k; j<k+a;j++) {ar[j]=i;}k+=a;
    }
    cin>>m;
    for (int i=1;i<=m;i++){
      cin>>q;
      cout<<ar[q]<<endl;
    }
}


#include <iostream>
using namespace std;
int k;
int ar[10001][2];
main (){
    cin>>n;
    for (int i=1;i<=n;i++){
        p=a;
        cin>>a;
        ar[i][0]=p+1;
        ar[i][1]=p+a;

    }
    cin>>m;
    for (int i=0;i<m;i++){
        cin>>q;
        for(int j=1;j<=n;j++){
            if(q>=ar[j][0] && q<=ar[j][1]) {
                cout<<j<<endl;
                break;
            }
        }
    }
}


#include <iostream>
using namespace std;
int p,m,a,q,n,k;
int ar[10001][2];
main (){
    cin>>n;
    for (int i=1;i<=n;i++){
        p+=a;
        cin>>a;
        ar[i][0]=p+1;
        ar[i][1]=p+a;

    }
    cin>>m;
    /*for(int j=1;j<=n;j++){
            cout<<ar[j][0]<<" "<<ar[j][1]<<endl;
    }*/
    for (int i=0;i<m;i++){
        cin>>q;
        for(int j=1;j<=n;j++){
            if(q>=ar[j][0] && q<=ar[j][1]) {

                cout<<j<<endl;
                break;
            }
        }
    }
}


#include <iostream>
using namespace std;
int p,m,a,q,k;
int ar[10001][2];
main (){
    cin>>n;
    for (int i=1;i<=n;i++){
        p=a;
        cin>>a;
        ar[i][0]=p+1;
        ar[i][1]=p+a;

    }
    cin>>m;
    for (int i=0;i<m;i++){
        cin>>q;
        for(int j=1;j<=n;j++){
            if(q>=ar[j][0] && q<=ar[j][1]) {
                cout<<j<<endl;
                break;
            }
        }
    }
}


#include <iostream>
using namespace std;
int p,m,a,q,n,k;
int ar[1000001];
main (){
    cin>>n;
    for (int i=1;i<=n;i++){

      cin>>a;
      for(int j=k; j<=k+a;j++) {ar[j]=i;}k+=a;
    }
    cin>>m;
    for (int i=1;i<=m;i++){
      cin>>q;
      cout<<ar[q]<<endl;
    }
}


#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;
        if(i==0)
            a[i]=p;
        else
            a[i]=a[i-1]+p;
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int p;
        cin>>p;
        int l=0;r=n-1,mid,index;
        while(l<=r)
        {
            if(a[mid]>=p &&(mid==0 || mid &&a[mid-1]<p))
            {
               // flag=true;
                index=mid+1;
                cout<<index<<endl;
                break;
            }
            else if(a[mid]>p)
            {
                l=mid-1;
            }
            else
                r=mid+1;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;
        if(i==0)
            a[i]=p;
        else
            a[i]=a[i-1]+p;
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int p;
        cin>>p;
        int l=0,r=n-1,mid,index;
        while(l<=r)
        {
            mid=(l+r)/2;
            if(a[mid]>=p &&(mid==0 || mid &&a[mid-1]<p))
            {
                //flag=true;
                index=mid+1;
                cout<<index<<endl;
                break;
            }
            else if(a[mid]>p)
            {
                r=mid-1;
            }
            else
                l=mid+1;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;
        if(i==0)
            a[i]=p;
        else
            a[i]=a[i-1]+p;
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int p;
        cin>>p;
        int l=0,r=n-1,mid,index;
        while(l<=r)
        {
            if(a[mid]>=p &&(mid==0 || mid &&a[mid-1]<p))
            {
                flag=true;
                index=mid+1;
                cout<<index<<endl;
                break;
            }
            else if(a[mid]>p)
            {
                l=mid-1;
            }
            else
                r=mid+1;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;
        if(i==0)
            a[i]=p;
        else
            a[i]=a[i-1]+p;
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int p;
        cin>>p;
        int l=0,r=n-1,mid,index;
        while(l<=r)
        {
            if(a[mid]>=p &&(mid==0 || mid &&a[mid-1]<p))
            {
                //flag=true;
                index=mid+1;
                cout<<index<<endl;
                break;
            }
            else if(a[mid]>p)
            {
                l=mid-1;
            }
            else
                r=mid+1;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;
        if(i==0)
            a[i]=p;
        else
            a[i]=a[i-1]+p;
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int p;
        cin>>p;
        int l=0,r=n-1,mid,index;
        while(l<=r)
        {
            mid=(l+r)/2;
            if(a[mid]>=p &&(mid==0 || mid &&a[mid-1]<p))
            {
                //flag=true;
                index=mid+1;
                cout<<index<<endl;
                break;
            }
            else if(a[mid]>p)
            {
                l=mid-1;
            }
            else
                r=mid+1;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;
        if(i==0)
            a[i]=p;
        else
            a[i]=a[i-1]+p;
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int p;
        cin>>p;
        int l=0;r=n-1,mid,index;
        while(l<=r)
        {
            if(a[mid]>=p &&(mid==0 || mid &&a[mid-1]<p))
            {
                flag=true;
                index=mid+1;
                cout<<index<<endl;
                break;
            }
            else if(a[mid]>p)
            {
                l=mid-1;
            }
            else
                r=mid+1;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;
        if(i==0)
            a[i]=p;
        else
            a[i]=a[i-1]+p;
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int p;
        cin>>p;
        int l=0,r=n-1,mid,index;
        while(l<=r)
        {
            if(a[mid]>=p &&(mid==0 || mid &&a[mid-1]<p))
            {
                //flag=true;
                index=mid+1;
                cout<<index<<endl;
                break;
            }
            else if(a[mid]>p)
            {
                r=mid-1;
            }
            else
                l=mid+1;
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        int p;
        cin>>p;
        if(i==0)
            a[i]=p;
        else
            a[i]=a[i-1]+p;
    }
    int m;
    cin>>m;
    for(int i=0;i<m;i++)
    {
        int p;
        cin>>p;
        int l=0;r=n-1,mid,index;
        while(l<=r)
        {
            if(a[mid]>=p &&(mid==0 || mid &&a[mid-1]<p))
            {
                flag=true;
                index=mid+1;
                cout<<index<<endl;
                break;
            }
            else if(a[mid]>p)
            {
                l=mid-1;
            }
            else
                r=mid+1;
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int n,i,a,j,x=1,d[1000000],m,b;
main(){
  cin>>n;
    for(i=1; i<=n; i++){
            cin>>a;
        for(j=x; j<=x+a-1; j++){
            d[j]=i;
        }
     x=x+a;
    }
 cin>>m;
   for(i=0; i<m; i++){
    cin>>b;
    cout<<d[b]<<endl;
   }

}


#include<bits/stdc++.h>
using namespace std;
int n,i,a,j,x=1,d[1000001],m,b;
main(){
  cin>>n;
    for(i=1; i<=n; i++){
            cin>>a;
        for(j=x; j<x+a; j++){
            d[j]=i;
        }
     x=x+a;
    }
 cin>>m;
   for(i=0; i<m; i++){
    cin>>b;
    cout<<d[b]<<endl;
   }

}


#include<bits/stdc++.h>
using namespace std;
int n,i,a,j,x=1,d[1000002],m,b;
main(){
  cin>>n;
    for(i=1; i<=n; i++){
            cin>>a;
        for(j=x; j<x+a; j++){
            d[j]=i;
        }
     x=x+a;
    }
 cin>>m;
   for(i=0; i<m; i++){
    cin>>b;
    cout<<d[b]<<endl;
   }

}


#include<bits/stdc++.h>
using namespace std;
int n,i,a,j,x=1,d[1000000],m,b;
main(){
  cin>>n;
    for(i=1; i<=n; i++){
            cin>>a;
        for(j=x; j<x+a; j++){
            d[j]=i;
        }
     x=x+a;
    }
 cin>>m;
   for(i=0; i<m; i++){
    cin>>b;
    cout<<d[b]<<endl;
   }

}


#include<iostream>
using namespace std;
int n,i,a,j,x=1,d[1000000],m,b;
main(){
  cin>>n;
    for(i=1; i<=n; i++){
            cin>>a;
        for(j=x; j<x+a; j++){
            d[j]=i;
        }
     x=x+a;
    }
 cin>>m;
   for(i=0; i<n; i++){
    cin>>b;
    cout<<d[b]<<endl;
   }

}


#include<bits/stdc++.h>
using namespace std;
int n,i,a,j,x=1,d[1000001],m,b;
main(){
  cin>>n;
    for(i=1; i<=n; i++){
            cin>>a;
        for(j=x; j<x+a; j++){
            d[j]=i;
        }
     x=x+a;
    }
 cin>>n;
   for(i=0; i<n; i++){
    cin>>a;
    cout<<d[a]<<endl;
   }

}


#include<iostream>
using namespace std;
int n,i,a,j,x=1,d[1000000],m,b;
main(){
  cin>>n;
    for(i=1; i<=n; i++){
            cin>>a;
        for(j=x; j<x+a; j++){
            d[j]=i;
        }
     x=x+a;
    }
 cin>>m;
   for(i=0; i<m; i++){
    cin>>b;
    cout<<d[b]<<endl;
   }

}


#include<bits/stdc++.h>
using namespace std;
int n,i,a,j,x=1,d[1000000],m,b;
main(){
  cin>>n;
    for(i=1; i<=n; i++){
            cin>>a;
        for(j=x; j<x+a; j++){
            d[j]=i;
        }
     x=x+a;
    }
 cin>>m;
   for(i=0; i<m; i++){
    cin>>a;
    cout<<d[a]<<endl;
   }

}


#include<bits/stdc++.h>
using namespace std;
int n,i,a,j,x=1,d[1000000],m,b;
main(){
  cin>>n;
    for(i=1; i<=n; i++){
            cin>>a;
        for(j=x; j<x+a; j++){
            d[j]=i;
        }
     x=x+a;
    }
 cin>>m;
   for(i=1; i<=m; i++){
    cin>>b;
    cout<<d[b]<<endl;
   }

}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,m,j=0,l=0,h=n-1,mid,temp=0;
	cin>>n;
	long long int a[n];
	for(long long int i=0; i<n;i++){
		cin>>a[i];
		if(i>0)
		a[i]=a[i]+a[i-1];
	}
	cin>>m;
	long long int b[m];
	for(long long int i=0; i<m;i++){
		cin>>b[i];
	}
	for(long long int i=0; i<m;i++){
 	 l=0;
 	 h=n-1;
 	 temp=(l+h)/2;
	 while(l<=h){
	mid=(l+h)/2;
 	 if(b[i]>a[mid]){
 	 l=mid+1;
	 }
	 if(b[i]<a[mid]){
	 h=mid-1;
	 }
	 if(b[i]==a[mid]){
	 j=mid;
	 break;
	 }
     }
     if(b[i]<a[temp])
 	 cout<<l+1<<endl;

 	 if(b[i]>a[temp])
	 cout<<h+1<<endl;

	 if(b[i]==a[temp])
	 cout<<mid+1<<endl;

}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,m,j=0,l=0,h=n-1,mid,temp=0;
	cin>>n;
	long long int a[n];
	for(long long int i=1; i<=n;i++){
		cin>>a[i];
		if(i>1)
		a[i]=a[i]+a[i-1];
	}
	cin>>m;
	long long int b[m];
	for(long long int i=1; i<=m;i++){
		cin>>b[i];
	}
	for(long long int i=1; i<=m;i++){
 	 l=1;
 	 h=n;
 	 temp=(l+h)/2;
	 while(l<=h){
	 mid=(l+h)/2;
 	 if(b[i]>a[mid]){
 	 l=mid+1;
	 }
	 if(b[i]<a[mid]){
	 h=mid-1;
	 }
	 if(b[i]==a[mid]){
	 cout<<mid;
	 break;

	 }
     }

	 if(b[i]!=a[mid])
 	 cout<<l<<endl;

}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,m,j=0,l=0,h=n-1,mid,temp=0;
	cin>>n;
	long long int a[n];
	for(long long int i=0; i<n;i++){
		cin>>a[i];
		if(i>0)
		a[i]=a[i]+a[i-1];
	}
	cin>>m;
	long long int b[m];
	for(long long int i=0; i<m;i++){
		cin>>b[i];
	}
	for(long long int i=0; i<m;i++){
 	 l=0;
 	 h=n-1;
	 while(l<=h){
	mid=(l+h)/2;
  	temp=mid;
 	 if(b[i]>a[mid]){
 	 l=mid+1;
	 }
	 if(b[i]<a[mid]){
	 h=mid-1;
	 }
	 if(b[i]==a[mid]){
	 j=mid;
	 break;
	 }
     }
//     if(b[i]<a[temp])
 	 cout<<l+1<<endl;

// 	 if(b[i]>a[temp])
//	 cout<<h+1<<endl;
//
//	 if(b[i]==a[temp])
//	 cout<<mid+1<<endl;

}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,m,j=0,l=0,h=n-1,mid,temp=0;
	cin>>n;
	long long int a[n];
	for(long long int i=0; i<n;i++){
		cin>>a[i];
		if(i>0)
		a[i]=a[i]+a[i-1];
	}
	cin>>m;
	long long int b[m];
	for(long long int i=0; i<m;i++){
		cin>>b[i];
	}
	for(long long int i=0; i<m;i++){
 	 l=0;
 	 h=n-1;
 	 temp=(l+h)/2;
	 while(l<=h){
	 mid=(l+h)/2;
 	 if(b[i]>a[mid]){
 	 l=mid+1;
	 }
	 if(b[i]<a[mid]){
	 h=mid-1;
	 }
	 if(b[i]==a[mid]){
	 cout<<mid+1<<endl;
	 break;

	 }
     }

	 if(b[i]!=a[mid])
 	 cout<<l+1<<endl;

}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,m,j=0,l=0,h=n-1,mid,temp=0;
	cin>>n;
	long long int a[n];
	for(long long int i=0; i<n;i++){
		cin>>a[i];
		if(i>0)
		a[i]=a[i]+a[i-1];
	}
	cin>>m;
	long long int b[m];
	for(long long int i=0; i<m;i++){
		cin>>b[i];
	}
	for(long long int i=0; i<m;i++){
 	 l=0;
 	 h=n-1;
 	 temp=(l+h)/2;
	 while(l<=h){
	 mid=(l+h)/2;
 	 if(b[i]>a[mid]){
 	 l=mid+1;
	 }
	 if(b[i]<a[mid]){
	 h=mid-1;
	 }
	 if(b[i]==a[mid]){
	 break;
	 cout<<mid+1;
	 }
     }

	 if(b[i]!=a[temp])
 	 cout<<l+1<<endl;

}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,m,j=0,l=0,h=n-1,mid,temp=0;
	cin>>n;
	long long int a[n];
	for(long long int i=1; i<=n;i++){
		cin>>a[i];
		if(i>1)
		a[i]=a[i]+a[i-1];
	}
	cin>>m;
	long long int b[m];
	for(long long int i=1; i<=m;i++){
		cin>>b[i];
	}
	for(long long int i=1; i<=m;i++){
 	 l=1;
 	 h=n;
 	 temp=(l+h)/2;
	 while(l<=h){
	 mid=(l+h)/2;
 	 if(b[i]>a[mid]){
 	 l=mid+1;
	 }
	 if(b[i]<a[mid]){
	 h=mid-1;
	 }
	 if(b[i]==a[mid]){
	 cout<<mid<<endl;
	 break;

	 }
     }

	 if(b[i]!=a[mid])
 	 cout<<l<<endl;

}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,m,j=0,l=0,h=n-1,mid,temp=0;
	cin>>n;
	long long int a[n];
	for(long long int i=1; i<=n;i++){
		cin>>a[i];
		if(i>1)
		a[i]=a[i]+a[i-1];
	}
	cin>>m;
	long long int b[m];
	for(long long int i=1; i<=m;i++){
		cin>>b[i];
	}
	for(long long int i=1; i<=m;i++){
 	 l=1;
 	 h=n;
 	 temp=(l+h)/2;
	 while(l<=h){
	 mid=(l+h)/2;
 	 if(b[i]>a[mid]){
 	 l=mid+1;
	 }
	 if(b[i]<a[mid]){
	 h=mid-1;
	 }
	 if(b[i]==a[mid]){
	 break;
	 cout<<mid;
	 }
     }

	 if(b[i]!=a[temp])
 	 cout<<l<<endl;

}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,m,j=0,l=0,h=n-1,mid,temp=0;
	cin>>n;
	long long int a[n];
	for(long long int i=0; i<n;i++){
		cin>>a[i];
		if(i>0)
		a[i]=a[i]+a[i-1];
	}
	cin>>m;
	long long int b[m];
	for(long long int i=0; i<m;i++){
		cin>>b[i];
	}
	for(long long int i=0; i<m;i++){
 	 l=0;
 	 h=n-1;
 	 temp=(l+h)/2;
	 while(l<=h){
	 mid=(l+h)/2;
 	 if(b[i]>a[mid]){
 	 l=mid+1;
	 }
	 if(b[i]<a[mid]){
	 h=mid-1;
	 }
	 if(b[i]==a[mid]){
	 break;
	 }
     }

 	 cout<<l+1<<endl;
 	 if(b[i]==a[temp])
     cout<<mid+1<<endl;

}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,m,k=0,j=0;
	cin>>n;
	long long int a[n];
	for(long long int i=0; i<n;i++){
		cin>>a[i];
		if(i>0)
		a[i]=a[i]+a[i-1];
	}
	cin>>m;
	long long int b[m];
	for(long long int i=0; i<m;i++){
		cin>>b[i];
	}
	for(long long int i=0; i<m;i++){
 	while(b[i]>a[j]){
 	    j++;

	 }
 	 cout<<j+1<<endl;
 	 j=0;
	}

return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(){
	long long int n,m,j=0,l=0,h=n-1,mid,temp=0;
	cin>>n;
	long long int a[n];
	for(long long int i=1; i<=n;i++){
		cin>>a[i];
		if(i>1)
		a[i]=a[i]+a[i-1];
	}
	cin>>m;
	long long int b[m];
	for(long long int i=1; i<=m;i++){
		cin>>b[i];
	}
	for(long long int i=1; i<=m;i++){
 	 l=1;
 	 h=n;
 	 temp=(l+h)/2;
	 while(l<=h){
	 mid=(l+h)/2;
 	 if(b[i]>a[mid]){
 	 l=mid+1;
	 }
	 if(b[i]<a[mid]){
	 h=mid-1;
	 }
	 if(b[i]==a[mid]){
	 break;
	 cout<<mid;
	 }
     }

	 if(b[i]!=a[mid])
 	 cout<<l<<endl;

}

return 0;
}


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

// int Findworm(vector <int> vec, int x, int l, int r){

//         if(r >= l){
//             int mid = (l + r)/ 2;
//             // cout << "\n mid is " << mid << "\n" ;

//                 return mid + 1;
//             else if(vec[mid] > x){
//                 return Findworm(vec, x, l, mid -1);
//             }
//             else
//                 return Findworm(vec, x, mid+1, r);
//         }
//         // else return r;
// }

int findworm(vector <int> vec, int x, int l, int r) {
    int mid = l + (r - l) / 2;
    while(l <= r) {
        if(vec[mid] >= x && vec[mid-1] < x)
            return mid + 1;
        else if(vec[mid] > x){
            r = mid +1;
        }
        else
            l = mid -1;
    }
}
int main(){
    int  n;
    cin >> n;
    int prev = 0;
    vector <int> vec1;
    while(n--){
        int x;
        cin >> x;
        x  += prev;
        vec1.push_back(x);
        prev = x;
    }
    int a;
    cin >> a;
    vector <int> vec2;
    while(a--){
        int x;
        cin >> x;
        vec2.push_back(x);;
    }
    for(auto i : vec2){
        if(i <= vec1[0])
            cout << "1 \n";
        else
            cout << findworm(vec1, i, 0, vec1.size()) << "\n";
    }
}


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

int Findworm(vector <int> vec, int x, int l, int r){

        if(r >= l){
            int mid = l + (r-1)/ 2;
            // cout << "\n mid is " << mid << "\n" ;
            if(vec[mid] >= x && vec[mid-1] < x)
                return mid + 1;
            else if(vec[mid] > x){
                return Findworm(vec, x, l, mid -1);
            }
            else
                return Findworm(vec, x, mid+1, r);
        }
        else return r;
}

int main(){
    int  n;
    cin >> n;
    int prev = 0;
    vector <int> vec1;
    while(n--){
        int x;
        cin >> x;
        x  += prev;
        vec1.push_back(x);
        prev = x;
    }
    int a;
    cin >> a;
    vector <int> vec2;
    while(a--){
        int x;
        cin >> x;
        vec2.push_back(x);;
    }
    for(auto i : vec2){
        if(i <= vec1[0])
            cout << "1 \n";
        else
            cout << Findworm(vec1, i, 0, vec1.size()) << "\n";
    }
}


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

int findworm(vector <int> vec, int x, int l, int r) {

    while(l <= r) {
        int mid = l + (r - l) / 2;
        if(vec[mid] >= x && vec[mid-1] < x)
            return mid + 1;
        else if(vec[mid] > x){
            r = mid - 1;
        }
        else
            l = mid  + 1;
    }
}
int main(){
    int  n;
    cin >> n;
    int prev = 0;
    vector <int> vec1;
    while(n--){
        int x;
        cin >> x;
        x  += prev;
        vec1.emplace_back(x);
        prev = x;
    }
    int a;
    cin >> a;
    vector <int> vec2;
    int p = a;
    while(p--){
        int x;
        cin >> x;
        vec2.emplace_back(x);
    }
    // for(auto i : vec2){
    //     if(i <= vec1[0])
    //         cout << "1 \n";
    //     else
    //         cout << findworm(vec1, i, 0, vec1.size()) << "\n";
    // }
    int prepile[a];
    for(int i = 0; i < a; i++) {
        if(vec2[i] <= vect1[0]){
            prepile[i] = 1;
        } else
        prepile[i] = findworm(vec1, i, 0, vec1.size());
    }
    for(int i = 0; i < a; i++) {
        cout << prepile[i] << endl;
    }
}


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

int Findworm(vector <int> vec, int x, int l, int r){

        if(r >= l){
            int mid = l + (r-1)/ 2;
            // cout << "\n mid is " << mid << "\n" ;
            if(vec[mid] >= x && vec[mid-1] < x)
                return mid + 1;
            else if(vec[mid] > x){
                return Findworm(vec, x, l, mid -1);
            }
            else
                return Findworm(vec, x, mid+1, r);
        }
}

int main(){
    int  n;
    cin >> n;
    int prev = 0;
    vector <int> vec1;
    while(n--){
        int x;
        cin >> x;
        x  += prev;
        vec1.push_back(x);
        prev = x;
    }
    int a;
    cin >> a;
    vector <int> vec2;
    while(a--){
        int x;
        cin >> x;
        vec2.push_back(x);;
    }
    for(auto i : vec2){
        if(i <= vec1[0])
            cout << "1 \n";
        else
            cout << Findworm(vec1, i, 0, vec1.size()) << "\n";
    }
}


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

int Findworm(vector <int> vec, int x, int l, int r){

        if(r >= l){
            int mid = l + (r-l)/ 2;
            // cout << "\n mid is " << mid << "\n" ;
            if(vec[mid] >= x && vec[mid-1] < x)
                return mid + 1;
            else if(vec[mid] > x){
                return Findworm(vec, x, l, mid -1);
            }
            else
                return Findworm(vec, x, mid+1, r);
        }
        else return r;
}

int main(){
    int  n;
    cin >> n;
    int prev = 0;
    vector <int> vec1;
    while(n--){
        int x;
        cin >> x;
        x  += prev;
        vec1.push_back(x);
        prev = x;
    }
    int a;
    cin >> a;
    vector <int> vec2;
    while(a--){
        int x;
        cin >> x;
        vec2.push_back(x);;
    }
    for(auto i : vec2){
        if(i <= vec1[0])
            cout << "1 \n";
        else
            cout << Findworm(vec1, i, 0, vec1.size()) << "\n";
    }
}


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

int Findworm(vector <int> vec, int x, int l, int r){

        if(r >= l){
            int mid = l + (r-1)/ 2;
            // cout << "\n mid is " << mid << "\n" ;
            if(vec[mid] >= x && vec[mid-1] < x)
                return mid + 1;
            else if(vec[mid] > x){
                return Findworm(vec, x, l, mid -1);
            }
            else
                return Findworm(vec, x, mid+1, r);
        }
}

int main(){
    int  n;
    cin >> n;
    int prev = 0;
    vector <int> vec1;
    while(n--){
        int x;
        cin >> x;
        x  += prev;
        vec1.push_back(x);
        prev = x;
    }
    cin >> n;
    vector <int> vec2;
    while(n--){
        int x;
        cin >> x;
        vec2.push_back(x);;
    }
    for(auto i : vec2){
        if(i <= vec1[0])
            cout << "1 \n";
        else
            cout << Findworm(vec1, i, 0, vec1.size()) << "\n";
    }
}


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

int pile[1000001];

int main() {
    int n; cin >> n;
    int a[n]; for (int i = 0; i < n; i++) cin >> a[i];
    int m; cin >> m;
    int b[m]; for (int i = 0; i < m; i++) cin >> b[i];
    int index = 1;
    for (int i = 0; i < n; i++) {
        for (int j = index; j < index + a[i]; j++) {
            pile[j] = i+1;
        }
        index += a[i];
    }
    for (int i = 0; i < m; i++) {
        cout << pile[b[i]] << "\n";
    }

    return 0;
}


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

int Findworm(vector <int> vec, int x, int l, int r){

        if(l <= r){
            int mid = l + (r-1)/ 2;
            // cout << "\n mid is " << mid << "\n" ;
            if(vec[mid] >= x && vec[mid-1] < x)
                return mid + 1;
            else if(vec[mid] > x){
                return Findworm(vec, x, l, mid -1);
            }
            else
                return Findworm(vec, x, mid+1, r);
        }
        else return r;
}

int main(){
    int  n;
    cin >> n;
    int prev = 0;
    vector <int> vec1;
    while(n--){
        int x;
        cin >> x;
        x  += prev;
        vec1.push_back(x);
        prev = x;
    }
    cin >> n;
    vector <int> vec2;
    while(n--){
        int x;
        cin >> x;
        vec2.push_back(x);;
    }
    for(auto i : vec2)
        cout << i << "\t";

    cout << endl;

    for(auto i : vec1)
        cout << i << "\t";

    cout << endl;
    for(auto i : vec2){
        if(i <= vec1[0])
            cout << "1 \n";
        else
            cout << Findworm(vec1, i, 0, vec1.size()) << "\n";
    }
}


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

// int Findworm(vector <int> vec, int x, int l, int r){

//         if(r >= l){
//             int mid = (l + r)/ 2;
//             // cout << "\n mid is " << mid << "\n" ;

//                 return mid + 1;
//             else if(vec[mid] > x){
//                 return Findworm(vec, x, l, mid -1);
//             }
//             else
//                 return Findworm(vec, x, mid+1, r);
//         }
//         // else return r;
// }

int findworm(vector <int> vec, int x, int l, int r) {

    while(l <= r) {
        int mid = l + (r - l) / 2;
        if(vec[mid] >= x && vec[mid-1] < x)
            return mid + 1;
        else if(vec[mid] > x){
            r = mid - 1;
        }
        else
            l = mid  + 1;
    }
}
int main(){
    int  n;
    cin >> n;
    int prev = 0;
    vector <int> vec1;
    while(n--){
        int x;
        cin >> x;
        x  += prev;
        vec1.push_back(x);
        prev = x;
    }
    int a;
    cin >> a;
    vector <int> vec2;
    while(a--){
        int x;
        cin >> x;
        vec2.push_back(x);;
    }
    for(auto i : vec2){
        if(i <= vec1[0])
            cout << "1 \n";
        else
            cout << findworm(vec1, i, 0, vec1.size()) << "\n";
    }
}


#include<bits/stdc++.h>

using namespace std;

int s[10009];
int main()
{
    int n;
    cin>>n;
    s[0]=0;
    for(int i=1; i<=n; i++)
    {
        int x;
        cin>>x;
        s[i]=s[i-1]+x;
    }
    int m;
    cin>>m;
    while(m>0)
    {
        int x,k=0;
        cin>>x;
        int l=1,h=n,mid;
        while(l<=h)
        {
             mid=(l+h)/2;
            if(x>s[mid-1] && x<=s[mid])
            {
                cout<<mid<<endl;
                k=1;
                break;
            }
            else if(x>s[mid])
                l=mid+1;
            else
                h=mid-1;
        }
        if(!k)
        {
            if(s[mid]>=x && s[mid-1]<x)
                cout<<mid<<endl;
            else if(s[mid+1]>=x && s[mid]<x)
                cout<<mid+1<<endl;
            else
                cout<<mid-1<<endl;
        }

        m--;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int s[10009];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        s[i]=s[i-1]+x;
    }
    int m;
    cin>>m;
    while(m>0){
        int x,k=0;
        cin>>x;
        int l=1,h=n;
        while(l<=h){
            int mid=(l+h)/2;
            if(s[mid]>=x && s[mid-1]<=x){
                cout<<mid<<endl;
                k=1;
                break;
            }
            else if(x>s[mid])
                l=mid+1;
            else
                h=mid-1;
        }
        if(!k){
                if(s[l]>=x && s[l]<=x)
                           cout<<l<<endl;
               else
                cout<<l-1<<endl;
        }

        m--;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int s[100009];
int main()
{
    int n;
    cin>>n;
    s[0]=0;
    for(int i=1; i<=n; i++)
    {
        int x;
        cin>>x;
        s[i]=s[i-1]+x;
    }
    int m;
    cin>>m;
    while(m>0)
    {
        int x,k=0;
        cin>>x;
        int l=1,h=n,mid;
        while(l<=h)
        {
             mid=(l+h)/2;
            if(x>s[mid-1] && x<=s[mid])
            {
                cout<<mid<<endl;
                k=1;
                break;
            }
            else if(x>s[mid])
                l=mid+1;
            else
                h=mid-1;
        }
        if(!k)
        {
            if(s[l]>=x && s[l-1]<x)
                cout<<l<<endl;
            else if(s[l+1]>=x && s[l]<x)
                cout<<l+1<<endl;
            else
                cout<<l-1<<endl;
        }

        m--;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int s[10009];
int main()
{
    int n;
    cin>>n;
    s[0]=0;
    for(int i=1; i<=n; i++)
    {
        int x;
        cin>>x;
        s[i]=s[i-1]+x;
    }
    int m;
    cin>>m;
    while(m>0)
    {
        int x,k=0;
        cin>>x;
        int l=1,h=n,mid;
        while(l<=h)
        {
             mid=(l+h)/2;
            if(x>s[mid-1] && x<=s[mid])
            {
                cout<<mid<<endl;
                k=1;
                break;
            }
            else if(x>=s[mid])
                l=mid+1;
            else
                h=mid-1;
        }
        if(!k)
        {
            if(s[mid]>=x && s[mid-1]<x)
                cout<<mid<<endl;
            else if(s[mid+1]>=x && s[mid]<x)
                cout<<mid+1<<endl;
            else
                cout<<mid-1<<endl;
        }

        m--;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int s[10009];
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int x;
        cin>>x;
        s[i]=s[i-1]+x;
    }
    int m;
    cin>>m;
    while(m>0){
        int x,k=0;
        cin>>x;
        int l=1,h=n;
        while(l<=h){
            int mid=(l+h)/2;
            if(s[mid]>=x && s[mid-1]<=x){
                cout<<mid<<endl;
                k=1;
                break;
            }
            else if(x>s[mid])
                l=mid+1;
            else
                h=mid-1;
        }
        if(!k)
            cout<<l<<endl;
        m--;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int s[10009];
int main()
{
    int n;
    cin>>n;
    for(int i=1; i<=n; i++)
    {
        int x;
        cin>>x;
        s[i]=s[i-1]+x;
    }
    int m;
    cin>>m;
    while(m>0)
    {
        int x,k=0;
        cin>>x;
        int l=1,h=n;
        while(l<=h)
        {
            int mid=(l+h)/2;
            if(s[mid]>=x && s[mid-1]<=x)
            {
                cout<<mid<<endl;
                k=1;
                break;
            }
            else if(x>s[mid])
                l=mid+1;
            else
                h=mid-1;
        }
        if(!k)
        {
            if(s[l]>=x && s[l-1]<=x)
                cout<<l<<endl;
            else
                cout<<l-1<<endl;
        }

        m--;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int s[10009];
int main()
{
    int n;
    cin>>n;
    s[0]=0;
    for(int i=1; i<=n; i++)
    {
        int x;
        cin>>x;
        s[i]=s[i-1]+x;
    }
    int m;
    cin>>m;
    while(m>0)
    {
        int x,k=0;
        cin>>x;
        int l=1,h=n,mid;
        while(l<=h)
        {
             mid=(l+h)/2;
            if(s[mid]>=x && s[mid-1]<=x)
            {
                cout<<mid<<endl;
                k=1;
                break;
            }
            else if(x>s[mid])
                l=mid+1;
            else
                h=mid-1;
        }
        if(!k)
        {
            if(s[mid]>=x && s[mid-1]<=x)
                cout<<l<<endl;
            else if(s[mid+1]>=x && s[mid]<=x)
                cout<<l+1<<endl;
            else
                cout<<l-1<<endl;
        }

        m--;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int s[10009];
int main()
{
    int n;
    cin>>n;
    s[0]=0;
    for(int i=1; i<=n; i++)
    {
        int x;
        cin>>x;
        s[i]=s[i-1]+x;
    }
    int m;
    cin>>m;
    while(m>0)
    {
        int x,k=0;
        cin>>x;
        int l=1,h=n,mid;
        while(l<=h)
        {
             mid=(l+h)/2;
            if(x>s[mid-1] && x<=s[mid])
            {
                cout<<mid<<endl;
                k=1;
                break;
            }
            else if(x>s[mid])
                l=mid+1;
            else
                h=mid-1;
        }
        if(!k)
        {
            if(s[l]>=x && s[l-1]<x)
                cout<<l<<endl;
            else if(s[l+1]>=x && s[l]<x)
                cout<<l+1<<endl;
            else
                cout<<l-1<<endl;
        }

        m--;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main (){

	int numOfPiles, t;
	cin >> numOfPiles;
	int piles[numOfPiles];

	for (int i = 0; i < numOfPiles; i++){
		cin >> t;
		piles[i] = t;
	}

	int juicy;
	cin >> juicy;
	int jWorms[juicy];

	for (int i = 0; i < juicy; i++){
		cin >> t;
		jWorms[i] = t;
	}

	for (int i = 0; i < juicy; i++){
		int target = jWorms[i];
		int low = 0;
		int high = numOfPiles - 1;
		bool found = false;
		int mid;

		while (low <= high){
			mid = (low + high) >> 1;
			int total = 0;

			for (int i = 0; i <= mid; i++){
				total += piles[i];
			}

			if (target >= (total - piles[mid]) && target <= total){
				found = true;
				break;
			}

			if (target < (total - piles[mid])){
				high = mid - 1;
			} else {
				low = mid + 1;
			}

		}

		cout << mid + 1 << endl;
	}

	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main (){

	int n, t, cum = 0;
	vector <int> a;
	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> t;
		cum += t;
		a.push_back(cum);
	}

	int m;
	cin >> m;

	for (int i = 0; i < m; i++){
		int target;
		cin >> target;
		int left = 0;
		int right = a.size()-1;

		while (left <= right){
			int mid = (left + right) / 2;

			if (mid == 0 && target <= a[mid]){
				cout << mid + 1 << endl;
				break;
			}

			if (target > a[mid-1] && target <= a[mid]){
				cout << mid + 1 << endl;
				break;
			}

			if (target > a[mid]){
				left = mid + 1;
			} else {
				right = mid - 1;
			}
		}

	}

	return 0;
}


#include <iostream>

using namespace std;

int main (){

	int numOfPiles, t;
	cin >> numOfPiles;
	int piles[numOfPiles];

	for (int i = 0; i < numOfPiles; i++){
		cin >> t;
		piles[i] = t;
	}

	int juicy;
	cin >> juicy;
	int jWorms[juicy];

	for (int i = 0; i < juicy; i++){
		cin >> t;
		jWorms[i] = t;
	}

	for (int i = 0; i < juicy; i++){
		int target = jWorms[i];
		int low = 0;
		int high = numOfPiles - 1;
		bool found = false;
		int mid;

		while (!found){
			mid = (low + high) >> 1;
			int total = 0;

			for (int i = 0; i <= mid; i++){
				total += piles[i];
			}

			if (target >= (total - piles[mid]) && target <= total){
				found = true;
				break;
			}

			if (target < (total - piles[mid])){
				high = mid - 1;
			} else {
				low = mid + 1;
			}

		}

		cout << mid + 1 << endl;
	}

	return 0;
}


#include <iostream>
#include <vector>

using namespace std;

int main (){

	int n, t, cum = 0;
	vector <int> a;
	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> t;
		cum += t;
		a.push_back(cum);
		cout << cum << endl;
	}

	int m;
	cin >> m;

	for (int i = 0; i < m; i++){
		int target;
		cin >> target;
		int left = 0;
		int right = a.size()-1;

		while (left <= right){
			int mid = (left + right) / 2;

			if (mid == 0 && target <= a[mid]){
				cout << mid + 1 << endl;
				break;
			}

			if (target > a[mid-1] && target <= a[mid]){
				cout << mid + 1 << endl;
				break;
			}

			if (target > a[mid]){
				left = mid + 1;
			} else {
				right = mid - 1;
			}
		}

	}

	return 0;
}

/**
 *
input
5
2 7 3 4 9
3
1 25 11
output
1
5
3

*/


#include <iostream>

using namespace std;

int main (){

	int numOfPiles, t;
	cin >> numOfPiles;
	int piles[numOfPiles];

	for (int i = 0; i < numOfPiles; i++){
		cin >> t;
		piles[i] = t;
	}

	int juicy;
	cin >> juicy;
	int jWorms[juicy];

	for (int i = 0; i < juicy; i++){
		cin >> t;
		jWorms[i] = t;
	}

	for (int i = 0; i < juicy; i++){
		int target = jWorms[i];
		int low = 0;
		int high = numOfPiles - 1;
		bool found = false;
		int mid;

		while (true){
			mid = (low + high) >> 1;
			int total = 0;

			for (int i = 0; i <= mid; i++){
				total += piles[i];
			}

			if (target >= (total - piles[mid]) && target <= total){
				found = true;
				break;
			}

			if (target < (total - piles[mid])){
				high = mid - 1;
			} else {
				low = mid + 1;
			}

		}

		cout << mid + 1 << endl;
	}

	return 0;
}


#include <iostream>

using namespace std;

int main (){

	int numOfPiles, t;
	cin >> numOfPiles;
	int piles[numOfPiles];

	for (int i = 0; i < numOfPiles; i++){
		cin >> t;
		piles[i] = t;
	}

	int juicy;
	cin >> juicy;
	int jWorms[juicy];

	for (int i = 0; i < juicy; i++){
		cin >> t;
		jWorms[i] = t;
	}

	for (int i = 0; i < juicy; i++){
		int target = jWorms[i];
		int low = 0;
		int high = numOfPiles - 1;
		bool found = false;
		int mid;

		while (!found){
			mid = (low + high) / 2;
			int total = 0;

			for (int i = 0; i <= mid; i++){
				total += piles[i];
			}

			if (target >= (total - piles[mid]) && target <= total){
				found = true;
				break;
			}

			if (target < (total - piles[mid])){
				high = mid - 1;
			} else {
				low = mid + 1;
			}

		}

		cout << mid + 1 << endl;
	}

	return 0;
}


#include <iostream>

using namespace std;

int main (){

	int numOfPiles, t;
	cin >> numOfPiles;
	int piles[numOfPiles];

	for (int i = 0; i < numOfPiles; i++){
		cin >> t;
		piles[i] = t;
	}

	int juicy;
	cin >> juicy;
	int jWorms[juicy];

	for (int i = 0; i < juicy; i++){
		cin >> t;
		jWorms[i] = t;
	}

	for (int i = 0; i < juicy; i++){
		int target = jWorms[i];
		int low = 0;
		int high = numOfPiles - 1;
		bool found = false;
		int mid;

		while (true){
			mid = (low + high) >> 1;
			int total = 0;

			for (int i = 0; i <= mid; i++){
				total += piles[i];
			}

			if (target >= (total - (piles[mid]) + 1) && target <= total){
				found = true;
				break;
			}

			if (target < (total - piles[mid])){
				high = mid - 1;
			} else {
				low = mid + 1;
			}

		}

		cout << mid + 1 << endl;
	}

	return 0;
}


#include <iostream>

using namespace std;

int main (){

	int numOfPiles, t;
	cin >> numOfPiles;
	int piles[numOfPiles];

	for (int i = 0; i < numOfPiles; i++){
		cin >> t;
		piles[i] = t;
	}

	int juicy;
	cin >> juicy;
	int jWorms[juicy];

	for (int i = 0; i < juicy; i++){
		cin >> t;
		jWorms[i] = t;
	}

	for (int i = 0; i < juicy; i++){
		int target = jWorms[i];
		int low = 0;
		int high = numOfPiles - 1;
		bool found = false;
		int mid;

		while (true){
			mid = (low + high) >> 1;
			int total = 0;

			for (int i = 0; i <= mid; i++){
				total += piles[i];
			}

			if (target >= (total - (piles[mid]-1)) && target <= total){
				found = true;
				break;
			}

			if (target < (total - piles[mid])){
				high = mid - 1;
			} else {
				low = mid + 1;
			}

		}

		cout << mid + 1 << endl;
	}

	return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long int
int main(){
    int n,i,j;
    cin>>n;
    ll arrn[n+1];
    arrn[0]=0;
    for(i=1;i<=n;i++){
        cin>>arrn[i];
    }
    int m;
    cin>>m;
    ll arrm[m];
    for(i=0;i<m;i++){
        cin>>arrm[i];
    }
    for(i=1;i<=n;i++){
        arrn[i]+=arrn[i-1];
    }
    for(i=0;i<m;i++){
        int ans=upper_bound(arrn,arrn+n,arrm[i])-arrn;
        cout<<ans+1<<" ";
    }
    return 0;
}


#include<iostream>
using namespace std;
#define ll long long int
int main(){
    int n,i,j;
    cin>>n;
    ll arrn[n+1];
    arrn[0]=0;
    for(i=1;i<=n;i++){
        cin>>arrn[i];
    }
    int m;
    cin>>m;
    ll arrm[m];
    for(i=0;i<m;i++){
        cin>>arrm[i];
    }
    for(i=1;i<=n;i++){
        arrn[i]+=arrn[i-1];
    }
    for(i=0;i<m;i++){
        int ans=upper_bound(arrn,arrn+n,arrm[i])-arrn;
        cout<<ans+1<<" ";
    }
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long int
int main(){
    int n,i,j;
    cin>>n;
    ll arrn[n+1];
    arrn[0]=0;
    for(i=1;i<=n;i++){
        cin>>arrn[i];
    }
    int m;
    cin>>m;
    ll arrm[m];
    for(i=0;i<m;i++){
        cin>>arrm[i];
    }
    for(i=1;i<=n;i++){
        arrn[i]+=arrn[i-1];
    }
    for(i=0;i<m;i++){
        int ans=upper_bound(arrn,arrn+n,arrm[i])-arrn;
        cout<<ans<<"\n";
    }
    return 0;
}


#include<iostream>
using namespace std;
#define ll long long int
int main(){
    int n,i,j;
    cin>>n;
    ll arrn[n+1];
    arrn[0]=0;
    for(i=1;i<=n;i++){
        cin>>arrn[i];
    }
    int m;
    cin>>m;
    ll arrm[m];
    for(i=0;i<m;i++){
        cin>>arrm[i];
    }
    for(i=1;i<=n;i++){
        arrn[i]+=arrn[i-1];
    }
    for(i=0;i<m;i++){
        int ans=upper_bound(arrn,arrn+n,arrm[i])-arr;
        cout<<ans+1<<" ";
    }
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long int
int main(){
    int n,i,j;
    cin>>n;
    ll arrn[n+1];
    arrn[0]=0;
    for(i=1;i<=n;i++){
        cin>>arrn[i];
    }
    int m;
    cin>>m;
    ll arrm[m];
    for(i=0;i<m;i++){
        cin>>arrm[i];
    }
    for(i=1;i<=n;i++){
        arrn[i]+=arrn[i-1];
    }
    for(i=0;i<m;i++){
        int ans=upper_bound(arrn,arrn+n,arrm[i])-arrn;
        cout<<ans+1<<"\n";
    }
    return 0;
}


#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long int
int main(){
    int n,i,j;
    cin>>n;
    ll arrn[n+1];
    arrn[0]=0;
    for(i=1;i<=n;i++){
        cin>>arrn[i];
    }
    int m;
    cin>>m;
    ll arrm[m];
    for(i=0;i<m;i++){
        cin>>arrm[i];
    }
    for(i=1;i<=n;i++){
        arrn[i]+=arrn[i-1];
    }
    for(i=0;i<m;i++){
        int ans=upper_bound(arrn,arrn+n,arrm[i]-1)-arrn;
        cout<<ans<<"\n";
    }
    return 0;
}


#include<iostream>
using namespace std;
#define ll long long int
int main(){
    int n,i,j;
    cin>>n;
    ll arrn[n+1];
    arrn[0]=0;
    for(i=1;i<=n;i++){
        cin>>arr[i];
    }
    int m;
    cin>>m;
    ll arrm[m];
    for(i=0;i<m;i++){
        cin>>arrm[i];
    }
    for(i=1;i<=n;i++){
        arrn[i]+=arrn[i-1];
    }
    for(i=0;i<m;i++){
        for(j=0;j<=n;i++){
            if(arrn[j]<=arrm[i]<=arrn[j+1]){
                cout<<i+1;
            }
        }
    }
    return 0;
}


#include<iostream>
using namespace std;
#define ll long long int
int main(){
    int n,i,j;
    cin>>n;
    ll arrn[n+1];
    arrn[0]=0;
    for(i=1;i<=n;i++){
        cin>>arrn[i];
    }
    int m;
    cin>>m;
    ll arrm[m];
    for(i=0;i<m;i++){
        cin>>arrm[i];
    }
    for(i=1;i<=n;i++){
        arrn[i]+=arrn[i-1];
    }
    for(i=0;i<m;i++){
        for(j=0;j<=n;i++){
            if(arrn[j]<=arrm[i]<=arrn[j+1]){
                cout<<i+1;
            }
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long int n, m, a[10100], x;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x;
		if(i == 0) a[i] = x;
		else a[i] = a[i - 1] + x;
	}
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> x;
		for(int j = 0; j < n; j++){
			if(!j && x <= a[j]) {cout << j + 1 << "\n"; break;}
			else if(j && x <= a[j] && x > a[j - 1]) {cout << j + 1 << "\n"; break;}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long int n, m, a[101010], x, b;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x;
		int X = x;
		while(x){
			a[b + x] = i + 1;
			x--;
		}
		b += X;
	}
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> x;
		cout << a[x] << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long int n, m, a[700000], x, b;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x;
		int X = x;
		while(x){
			a[b + x] = i + 1;
			x--;
		}
		b += X;
	}
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> x;
		cout << a[x] << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long int n, m, a[60000], x;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x;
		if(i == 0) a[i] = x;
		else a[i] = a[i - 1] + x;
	}
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> x;
		for(int j = 0; j < n; j++){
			if(!j && x <= a[j]) {cout << j + 1 << "\n"; break;}
			else if(j && x <= a[j] && x > a[j - 1]) {cout << j + 1 << "\n"; break;}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long int n, m, a[100000010], x;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x;
		if(i == 0) a[i] = x;
		else a[i] = a[i - 1] + x;
	}
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> x;
		for(int j = 0; j < n; j++){
			if(!j && x <= a[j]) {cout << j + 1 << "\n"; break;}
			else if(j && x <= a[j] && x > a[j - 1]) {cout << j + 1 << "\n"; break;}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long int n, m, a[700000], x;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x;
		if(i == 0) a[i] = x;
		else a[i] = a[i - 1] + x;
	}
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> x;
		for(int j = 0; j < n; j++){
			if(!j && x <= a[j]) {cout << j + 1 << "\n"; break;}
			else if(j && x <= a[j] && x > a[j - 1]) {cout << j + 1 << "\n"; break;}
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long int n, m, a[700000], x;
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(i) a[i] += a[i - 1];
	}
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> x;
		cout << lower_bound(a, a + n, x) - a + 1 << "\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
long long int n, m, x;
pair <int, int> p[200000];
int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> x;
		if(!i){
			p[i].first = 1;
			p[i].second = x;
		}
		else{
			p[i].first = p[i - 1].second + 1;
			p[i].second = p[i].first + x - 1;
		}
	}
	cin >> m;
	for(int i = 0; i < m; i++){
		cin >> x;
		for(int j = 0; j < n; j++){
			if(x >= p[j].first && x <= p[j].second){
				cout << j + 1 << "\n";
				break;
			}
		}
	}
	return 0;
}


#include<bits/stdc++.h>

#define ll long long
using namespace std;
int main()
{
    int n,cnt=0;
    cin>>n;
    int a[n+3];
    vector<ll> v(n);
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    v[++cnt]=a[0];
    for(int i=1; i<n; i++)
    {
        int j=cnt;
        v[++cnt]=v[j]+a[i];
    }
    int q;
    cin>>q;
    while(q--)
    {
        int p;
        cin>>p;
        cout<<upper_bound(v.begin(),v.end(),p)-v.begin()<<endl;
    }

}


#include<bits/stdc++.h>

#define ll long long
using namespace std;
int main()
{
    int n,sum=0;
    cin>>n;
    int a[n+3];
    vector<int> v;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        sum+=a[i];
        v.push_back(sum);
    }
    int q;
    cin>>q;
    while(q--)
    {
        int p;
        cin>>p;
        cout<<(lower_bound(v.begin(),v.end(),p)-v.end())+6<<endl;
        /*for(int i=0; i<v.size(); i++)
        {
            if(p<=v[i])
            {
                cout<<i+1<<endl;
                break;
            }
        }*/
    }

}


#include<bits/stdc++.h>

#define ll long long
using namespace std;
int main()
{
    int n,cnt=0;
    cin>>n;
    int a[n+3];
    int b[n+300];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    b[++cnt]=a[0];
    for(int i=1; i<n; i++)
    {
        int j=cnt;
        b[++cnt]=b[j]+a[i];
    }

    int q;
    cin>>q;
    while(q--)
    {
        int p;
        cin>>p;
        for(int i=1; i<=cnt; i++)
        {
            if(p<=b[i])
            {
                cout<<i<<endl;
                break;
            }
        }
    }

}


#include<bits/stdc++.h>

#define ll long long
using namespace std;
int main()
{
    ll n,cnt=0;
    cin>>n;
    ll a[n+3];
    ll b[n+300];
    for(ll i=0; i<n; i++)
    {
        cin>>a[i];
    }
    b[++cnt]=a[0];
    for(ll i=1; i<n; i++)
    {
        ll j=cnt;
        b[++cnt]=b[j]+a[i];
    }

    ll q;
    cin>>q;
    while(q--)
    {
        ll p;
        cin>>p;
        for(ll i=1; i<=cnt; i++)
        {
            if(p<=b[i])
            {
                cout<<i<<endl;
                break;
            }
        }
    }

}


#include<bits/stdc++.h>

#define ll long long
using namespace std;
int main()
{
    int n,cnt=0;
    cin>>n;
    ll a[n+3];
    ll b[n+300];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    b[++cnt]=a[0];
    for(int i=1; i<n; i++)
    {
        int j=cnt;
        b[++cnt]=b[j]+a[i];
    }

    int q;
    cin>>q;
    while(q--)
    {
        ll p;
        cin>>p;
        for(int i=1; i<=cnt; i++)
        {
            if(p<=b[i])
            {
                cout<<i<<endl;
                break;
            }
        }
    }

}


#include<bits/stdc++.h>

#define ll long long
using namespace std;
int main()
{
    int n,sum=0;
    cin>>n;
    int a[n+3];
    vector<int> v;
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
        sum+=a[i];
        v.push_back(sum);
    }
    int q;
    cin>>q;
    while(q--)
    {
        int p;
        cin>>p;
        for(int i=0; i<v.size(); i++)
        {
            if(p<=v[i])
            {
                cout<<i+1<<endl;
                break;
            }
        }
    }

}


#include<bits/stdc++.h>

#define ll long long
using namespace std;
int main()
{
    int n,cnt=0;
    cin>>n;
    int a[n+3];
    int b[n+300];
    for(int i=0; i<n; i++)
    {
        cin>>a[i];
    }
    b[++cnt]=a[0];
    for(int i=1; i<n; i++)
    {
        int j=cnt;
        b[++cnt]=b[j]+a[i];
    }
    for(int i=1; i<=cnt;i++)
    {
        cout<<b[i]<<" ";
    }
    int q;
    cin>>q;
    while(q--)
    {
        int p;
        cin>>p;
        for(int i=1; i<=cnt; i++)
        {
            if(p<=b[i])
            {
                cout<<i<<endl;
                break;
            }
        }
    }

}


#include<bits/stdc++.h>

#define ll long long
using namespace std;
int main()
{
    int n,sum=0;
    cin>>n;
    int a[n+3];
    vector<int> v;
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        sum+=a[i];
        v.resize(sum,i);
    }
    int q;
    cin>>q;
    while(q--)
    {
        int p;
        cin>>p;
        cout<<v[p-1]<<endl;
        /*for(int i=0; i<v.size(); i++)
        {
            if(p<=v[i])
            {
                cout<<i+1<<endl;
                break;
            }
        }*/
    }

}


#include<iostream>
using namespace std;
int main()
{
    long int n,m;
    cin>>n;
   long int a[n],sum=0,s[n],t;
    for(long int i=0;i<n;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
        s[i]=sum;
    }
    cin>>m;
    while(m--)
    {
        cin>>t;
        for(long int j=0;j<n;j++)
       {
           if (t<=s[j])
           {
               cout<<j+1;
               cout<<endl;
               break;
           }
       }
   }

   return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n,m;
    scanf("%d",&n);
   int a[n],sum=0,s[n],t;
    for( int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
        s[i]=sum;
    }
    scanf("%d",&m);
	while(m!=0)
	{
		scanf("%d",&t);
		int low=0;
		int high=n-1;
		while(low<=high)
		{
			int mid=(low+high)/2;
			if (s[mid]>=t)
				high=mid-1;
			else
				low=mid+1;
		}
		printf("%d \n",low+1);
		m--;
	}
}


#include<iostream>
using namespace std;
int main()
{
    int n,m;
    cin>>n;
    int a[n],sum=0,s[n],lbl[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
        s[i]=sum;
    }
    cin>>m;

   for(int i=0;i<m;i++)
   {
       cin>>lbl[i];
   }
   for(int i=0;i<m;i++)
   {
       for(int j=0;j<n;j++)
       {
           if (a[i]<==s[j])
           {
               print j;
               break;
           }
       }
   }

   return 0;
}


#include<iostream>
using namespace std;
int main()
{
    long int n,m;
    cin>>n;
   long int a[n],sum=0,s[n],t;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
        s[i]=sum;
    }
    cin>>m;
    while(m--)
    {
        cin>>t;
        for(int j=0;j<n;j++)
       {
           if (t<=s[j])
           {
               cout<<j+1;
               cout<<endl;
               break;
           }
       }
   }

   return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n,m;
    cin>>n;
   int a[n],sum=0,s[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
        s[i]=sum;
    }
    cin>>m;
    int lbl[m];

   for(int i=0;i<m;i++)
   cin>>lbl[i];

   for(int i=0;i<m;i++)
   {
       for(int j=0;j<n;j++)
       {
           if (lbl[i]<=s[j])
           {
               cout<<j+1;
               cout<<endl;
               break;
           }
       }
   }

   return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n,m;
    cin>>n;
   long int a[n],sum=0,s[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
        s[i]=sum;
    }
    cin>>m;
    long int lbl[m];

   for(int i=0;i<m;i++)
   cin>>lbl[i];

   for(int i=0;i<m;i++)
   {
       for(int j=0;j<n;j++)
       {
           if (lbl[i]<=s[j])
           {
               cout<<j+1;
               cout<<endl;
               break;
           }
       }
   }

   return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n,m;
    cin>>n;
   long long int a[n],sum=0,s[n],lbl[100000];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
        s[i]=sum;
    }
    cin>>m;

   for(int i=0;i<m;i++)
   cin>>lbl[i];

   for(int i=0;i<m;i++)
   {
       for(int j=0;j<n;j++)
       {
           if (lbl[i]<=s[j])
           {
               cout<<j+1;
               cout<<endl;
               break;
           }
       }
   }

   return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n,m;
    scanf("%d",&n);
   int a[n],sum=0,s[n],t;
    for( int i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
        s[i]=sum;
    }
    scanf("%d",&m);
    while(m--)
    {
        scanf("%d",&t);
        for(int j=0;j<n;j++)
       {
           if (t<=s[j])
           {
               printf("%d \n",j+1);
               break;
           }
       }
   }

   return 0;
}


#include<iostream>
using namespace std;
int main()
{
    int n,m;
    cin>>n;
   long int a[n],sum=0,s[n],t;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum=sum+a[i];
        s[i]=sum;
    }
    cin>>m;
    while(m--)
    {
        cin>>t;
        for(int j=0;j<n;j++)
       {
           if (t<=s[j])
           {
               cout<<j+1;
               cout<<endl;
               break;
           }
       }
   }

   return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{

	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

	int n,m;
	int a[100002];
	cin>>n;
	int s=0;
	for(int i = 0 ; i < n ; i++)
	{
		int tmp;
	    cin>>tmp;
	    s += tmp;
	    a[i]=s;
	}
	int hi,lo,mid;
	cin>>m;
	int i;
	for(int j = 0 ; j < m ; j++)
	{

		cin>>i;
	    hi=n-1;
	    lo=-1;
	    while (hi-lo > 1)
	    {
	        mid = (hi + lo)/2;
	        if (a[mid]>=i)
	        {
	            hi = mid;
	        }
	        if (a[mid]<=i)
	        {
	            lo = mid;
	        }
	        cout<<"looped";
	    }
	    cout<<hi+1<<endl;

	}

}


#include<bits/stdc++.h>

using namespace std;

int main()
{

	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

	int n,m;
	int a[100002];
	cin>>n;
	int s=0;
	for(int i = 0 ; i < n ; i++)
	{
		int tmp;
	    cin>>tmp;
	    s += tmp;
	    a[i]=s;
	}
	int hi,lo,mid;
	cin>>m;
	int i;
	for(int j = 0 ; j < m ; j++)
	{

		cin>>i;
	    hi=n-1;
	    lo=-1;
	    while (hi-lo > 1)
	    {
	        mid = (hi + lo)/2;
	        if (a[mid]>=i)
	        {
	            hi = mid;
	        }
	        if (a[mid]<=i)
	        {
	            lo = mid;
	        }
	        //cout<<"looped";
	    }
	    cout<<hi+1<<endl;

	}

}


#include<bits/stdc++.h>

using namespace std;

int main()
{
int n,m,a[100002],q[100005];
cin>>n;
int s;
for(int i = 0 ; i < n ; i++)
{
    cin>>a[i];
    s += a[i];
    a[i]=s;
}
int hi,lo,mid;
cin>>m;
for(int j = 0 ; j < m ; j++)
{
	int i;
	cin>>i;
    hi=n-1;
    lo=-1;
    while (hi-lo > 1)
    {
        mid = (hi + lo)/2;
        if (a[mid]>i)
            hi = mid;
        if (a[mid]<i)
            lo = mid;
    }
    cout<<hi+1<<endl;

}

}


#include<bits/stdc++.h>

using namespace std;

int main()
{

	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

	int n,m;
	int a[1000002];
	cin>>n;
	int s=0;
	for(int i = 0 ; i < n ; i++)
	{
		int tmp;
	    cin>>tmp;
	    s += tmp;
	    a[i]=s;
	}
	int hi,lo,mid;
	cin>>m;
	int i;
	for(int j = 0 ; j < m ; j++)
	{

		cin>>i;
	    hi=n-1;
	    lo=-1;
	    while (hi-lo > 1)
	    {
	        mid = (hi + lo)/2;
	        if (a[mid]>i)
	        {
	            hi = mid;
	        }
	        if (a[mid]<i)
	        {
	            lo = mid;
	        }
	    }
	    cout<<hi+1<<endl;

	}

}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n,m;
	int a[100002];
	cin>>n;
	int s=0;
	for(int i = 0 ; i < n ; i++)
	{
	    cin>>a[i];
	    s += a[i];
	    a[i]=s;
	}
	int hi,lo,mid;
	cin>>m;
	int i;
	for(int j = 0 ; j < m ; j++)
	{

		cin>>i;
	    hi=n-1;
	    lo=-1;
	    while (hi-lo > 1)
	    {
	        mid = (hi + lo)/2;
	        if (a[mid]>i)
	        {
	            hi = mid;
	        }
	        if (a[mid]<i)
	        {
	            lo = mid;
	        }
	    }
	    cout<<hi+1<<endl;

	}

}


#include<bits/stdc++.h>

using namespace std;

int main()
{

	ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);

	int n,m;
	int a[100002];
	cin>>n;
	int s=0;
	for(int i = 0 ; i < n ; i++)
	{
	    cin>>a[i];
	    s += a[i];
	    a[i]=s;
	}
	int hi,lo,mid;
	cin>>m;
	int i;
	for(int j = 0 ; j < m ; j++)
	{

		cin>>i;
	    hi=n-1;
	    lo=-1;
	    while (hi-lo > 1)
	    {
	        mid = (hi + lo)/2;
	        if (a[mid]>i)
	        {
	            hi = mid;
	        }
	        if (a[mid]<i)
	        {
	            lo = mid;
	        }
	    }
	    cout<<hi+1<<endl;

	}

}


#include<bits/stdc++.h>

using namespace std;

int main()
{
	int n,m;
	long long a[100002];
	cin>>n;
	long long s=0;
	for(int i = 0 ; i < n ; i++)
	{
	    cin>>a[i];
	    s += a[i];
	    a[i]=s;
	}
	int hi,lo,mid;
	cin>>m;
	for(int j = 0 ; j < m ; j++)
	{
		int i;
		cin>>i;
	    hi=n-1;
	    lo=-1;
	    while (hi-lo > 1)
	    {
	        mid = (hi + lo)/2;
	        if (a[mid]>i)
	        {
	            hi = mid;
	        }
	        if (a[mid]<i)
	        {
	            lo = mid;
	        }
	    }
	    cout<<hi+1<<endl;

	}

}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
    int t;
    cin >> t;
    for (int k = 0; k < t; ++k) {
        int n;
        cin >> n;
        vector <int> a;
        int time = 0;
        int h = 0;
        for (int i = 0; i < n; ++i) {
            int x;
            cin >> x;
            a.push_back(x);
            while (a[i] + h < a[i-1]) {
                if (h == 0) {
                    h = 1;
                    ++time;
                } else {
                    h += h*2;
                    ++time;
                }
            }
            a[i] += h;
         }
         cout << time << "\n";
    }
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
    int t;
    cin >> t;
    for (int k = 0; k < t; ++k) {
        int n;
        cin >> n;
        int y;
        cin >> y;
        int u = 0;
        int r = 1;
        int time = 0;
        int maxt = y;
        int maxr = 0;
        for (int i = 1; i < n; ++i) {
            int x;
            cin >> x;
            if (x > maxt) maxt = x; else {
                if (maxt - x > maxr) maxr = maxt - x;
            }
        }
        cout << maxr;
        while (u < maxr) {
            u += r;
            r *= 2;
            ++time;
        }
        cout << time << "\n";
    }
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
    int t;
    cin >> t;
    for (int k = 0; k < t; ++k) {
        int n;
        cin >> n;
        vector <int> a;
        int t = 0;
        int h = 0;
        for (int i = 0; i < n; ++i) {
            int x;
            cin >> x;
            a.push_back(x);
            while (a[i] + h < a[i-1]) {
                if (h == 0) {
                    h = 1;
                    ++t;
                } else {
                    h += h*2;
                    ++t;
                }
            }
            a[i] += h;
         }
         cout << t << "\n";
    }
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
    int t;
    cin >> t;
    for (int k = 0; k < t; ++k) {
        int n;
        cin >> n;
        int y;
        cin >> y;
        int u = 1;
        int time = 0;
        for (int i = 1; i < n; ++i) {
            int x;
            cin >> x;
            int h = x;
            while (x < y) {
                ++time;
                x += u;
                u *= 2;
            }
            y = h;
        }
        cout << time << "\n";
    }
}


#include <bits/stdc++.h>

using namespace std;

#define int long long

int32_t main() {
    int t;
    cin >> t;
    for (int k = 0; k < t; ++k) {
        int n;
        cin >> n;
        int y;
        cin >> y;
        int u = 0;
        int time = 0;
        int maxt = y;
        int maxr = 0;
        for (int i = 1; i < n; ++i) {
            int x;
            cin >> x;
            if (x > maxt) maxt = x; else {
                if (maxt - x > maxr) maxr = maxt - x;
            }
        }
        while (u < maxr) {
            if (u == 0) u = 1; else {
                u *= 2;
            }
            ++time;
        }
        cout << time << "\n";
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>vec(n);
        vector<ll>vec1(n);
        for(ll i=0;i<n;i++)
        {
            cin>>vec.at(i);
            vec1.at(i)=vec.at(i);
        }
        sort(vec1.begin(),vec1.end());
        vector<ll>vec2;set<ll>s;
        ll q=n-1,k1=0;
        for(ll a=n-1;a>=0;a--)
        {

            if(q>=0&&vec.at(a)<vec1.at(q))
            {
                vec2.push_back(vec1.at(q)-vec.at(a));
                s.insert(vec.at(a));
            }
            if(q>=0&&vec.at(a)>=vec1.at(q))
            {
                ll k=s.size();
                while(k>=s.size())
                {
                    q--;
                    if(q==-1){k1++;break;}
                    s.insert(vec1.at(q));

                }
            }
            if(k1>0)break;

        }
        ll max=0;
        for(ll a=0;a<vec2.size();a++)
        {
            if(vec2.at(a)>max)
            max=vec2.at(a);
        }
        ll a;
        if(max==0)cout<<0<<endl;

        else
        {a=log2(max+2);
        cout<<a<<endl;}
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>vec(n);
        vector<ll>vec1(n);
        for(ll i=0;i<n;i++)
        {
            cin>>vec.at(i);
            vec1.at(i)=vec.at(i);
        }
        sort(vec1.begin(),vec1.end());
        vector<ll>vec2;set<ll>s;
        ll q=n-1,k1=0;
        for(ll a=n-1;a>=0;a--)
        {

            if(q>=0&&vec.at(a)<=vec1.at(q))
            {
                vec2.push_back(vec1.at(q)-vec.at(a));
                s.insert(vec.at(a));
            }
            if(q>=0&&vec.at(a)>=vec1.at(q))
            {
                ll k=s.size();
                while(k>=s.size())
                {
                    q--;
                    if(q==-1){k1++;break;}
                    s.insert(vec1.at(q));

                }
            }
            if(k1>0)break;

        }
        ll max{INT_MIN};
        for(ll a=0;a<vec2.size();a++)
        {
            if(vec2.at(a)>max)
            max=vec2.at(a);
        }
        ld a;
        a=log2(max+1);
        cout<<ceil(a)<<fixed<<setprecision(0)<<endl;

    }
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>vec(n);
        vector<ll>vec1(n);
        for(ll i=0;i<n;i++)
        {
            cin>>vec.at(i);
            vec1.at(i)=vec.at(i);
        }
        sort(vec1.begin(),vec1.end());
        vector<ll>vec2;set<ll>s;
        ll q=n-1,k1=0;
        for(ll a=n-1;a>=0;a--)
        {

            if(q>=0&&vec.at(a)<=vec1.at(q))
            {
                vec2.push_back(vec1.at(q)-vec.at(a));

            }
            if(q>=0&&vec.at(a)>=vec1.at(q))
            {
                ll k=s.size();
                while(k>=s.size())
                {
                    q--;
                    if(q==-1){k1++;break;}
                    s.insert(vec1.at(q));

                }
            }
            if(k1>0)break;
            s.insert(vec.at(a));
        }
        ll max{INT_MIN};
        for(ll a=0;a<vec2.size();a++)
        {
            if(vec2.at(a)>max)
            max=vec2.at(a);
        }
        ld a;
        a=log2(max+1);
        cout<<ceil(a)<<fixed<<setprecision(0)<<endl;

    }
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>vec(n);
        vector<ll>vec1(n);
        for(ll i=0;i<n;i++)
        {
            cin>>vec.at(i);
            vec1.at(i)=vec.at(i);
        }
        sort(vec1.begin(),vec1.end());
        vector<ll>vec2;set<ll>s;
        ll q=n-1,k1=0;
        for(ll a=n-1;a>=0;a--)
        {

            if(q>=0&&vec.at(a)<=vec1.at(q))
            {
                vec2.push_back(vec1.at(q)-vec.at(a));

            }
            if(q>=0&&vec.at(a)>=vec1.at(q))
            {
                ll k=s.size();
                while(k==s.size())
                {
                    q--;
                    if(q==-1){k1++;break;}
                    s.insert(vec1.at(q));

                }
            }
            if(k1>0)break;
            s.insert(vec.at(a));
        }
        ll max{INT_MIN};
        for(ll a=0;a<vec2.size();a++)
        {
            if(vec2.at(a)>max)
            max=vec2.at(a);
        }
        ld a;
        a=log2(max+1);
        cout<<ceil(a)<<fixed<<setprecision(0)<<endl;

    }
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>vec(n);
        vector<ll>vec1(n);
        for(ll i=0;i<n;i++)
        {
            cin>>vec.at(i);
            vec1.at(i)=vec.at(i);
        }
        sort(vec1.begin(),vec1.end());
        vector<ll>vec2;set<ll>s;
        ll q=n-1,k1=0;
        for(ll a=n-1;a>=0;a--)
        {

            if(q>=0&&vec.at(a)<vec1.at(q))
            {
                vec2.push_back(vec1.at(q)-vec.at(a));
                s.insert(vec.at(a));
            }
            if(q>=0&&vec.at(a)>=vec1.at(q))
            {
                ll k=s.size();
                while(k>=s.size())
                {
                    q--;
                    if(q==-1){k1++;break;}
                    s.insert(vec1.at(q));

                }
            }
            if(k1>0)break;

        }
        ll max=0;
        for(ll a=0;a<vec2.size();a++)
        {
            if(vec2.at(a)>max)
            max=vec2.at(a);
        }
        ld a;
        a=log2(max+1);
        cout<<ceil(a)<<fixed<<setprecision(0)<<endl;

    }
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>vec(n);
        vector<ll>vec1(n);
        for(ll i=0;i<n;i++)
        {
            cin>>vec.at(i);
            vec1.at(i)=vec.at(i);
        }
        sort(vec1.begin(),vec1.end());
        vector<ll>vec2;set<ll>s;
        ll q=n-1,k1=0;
        for(ll a=n-1;a>=0;a--)
        {

            if(vec.at(a)<vec1.at(q))
            {
                vec2.push_back(vec1.at(q)-vec.at(a));
            }
            if(vec.at(a)>=vec1.at(q)&&q>=0)
            {
                ll k=s.size();
                while(k>=s.size())
                {
                    q--;
                    if(q==-1){k1++;break;}
                    s.insert(vec1.at(q));

                }
            }
            if(k1>0)break;
            s.insert(vec.at(a));
        }
        ll max=0;
        for(ll a=0;a<vec2.size();a++)
        {
            if(vec2.at(a)>max)
            max=vec2.at(a);
        }
        ld a;
        a=log2(max+1);
        cout<<ceil(a)<<fixed<<setprecision(0)<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>vec(n);
        vector<ll>vec1(n);
        for(ll i=0;i<n;i++)
        {
            cin>>vec.at(i);
            vec1.at(i)=vec.at(i);
        }
        sort(vec1.begin(),vec1.end());
        vector<ll>vec2;set<ll>s;
        ll q=n-1,k1=0;
        for(ll a=n-1;a>=0;a--)
        {
            s.insert(vec.at(a));
            if(vec.at(a)<vec1.at(q))
            {
                vec2.push_back(vec1.at(q)-vec.at(a));
            }
            if(vec.at(a)==vec1.at(q)&&q>=0)
            {
                ll k=s.size();
                while(k>=s.size())
                {
                    q--;
                    if(q==-1){k1++;break;}
                    s.insert(vec1.at(q));

                }
            }
            if(k1>0)break;
        }
        ll max=0;
        for(ll a=0;a<vec2.size();a++)
        {
            if(vec2.at(a)>max)
            max=vec2.at(a);
        }
        ld a;
        a=log2(max+1);
        cout<<ceil(a)<<fixed<<setprecision(0)<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>vec(n);
        for(ll a=0;a<n;a++)
        {
            cin>>vec.at(a);
        }
        vector<ll>vec1(n,0);
        for(ll a=1;a<n;a++)
        {
            if(vec.at(a)-vec.at(a-1)<0)
            {
                vec1.at(a)=vec.at(a-1)-vec.at(a);
                vec.at(a)=vec.at(a-1);
            }
        }
        ll m{INT_MIN};
        for(ll a=0;a<n;a++)
        {
            if(vec1.at(a)>m)
            {
                m=vec1.at(a);
            }
        }
        ld a;
        a=log2(m+1);
        cout<<ceil(a)<<fixed<<setprecision(0)<<endl;
    }
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>vec(n);
        vector<ll>vec1(n);
        for(ll i=0;i<n;i++)
        {
            cin>>vec.at(i);
            vec1.at(i)=vec.at(i);
        }
        sort(vec1.begin(),vec1.end());
        vector<ll>vec2;set<ll>s;
        ll q=n-1,k1=0;
        for(ll a=n-1;a>=0;a--)
        {

            if(q>=0&&vec.at(a)<vec1.at(q))
            {
                vec2.push_back(vec1.at(q)-vec.at(a));
                s.insert(vec.at(a));
            }
            if(q>=0&&vec.at(a)>=vec1.at(q))
            {
                ll k=s.size();
                while(k>=s.size())
                {
                    q--;
                    if(q==-1){k1++;break;}
                    s.insert(vec1.at(q));

                }
            }
            if(k1>0)break;

        }
        ll max{INT_MIN};
        for(ll a=0;a<vec2.size();a++)
        {
            if(vec2.at(a)>max)
            max=vec2.at(a);
        }
        ld a;
        a=log2(max+1);
        cout<<ceil(a)<<fixed<<setprecision(0)<<endl;

    }
}


#include<bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t;
    cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        vector<ll>vec(n);
        vector<ll>vec1(n);
        for(ll i=0;i<n;i++)
        {
            cin>>vec.at(i);
            vec1.at(i)=vec.at(i);
        }
        sort(vec1.begin(),vec1.end());
        vector<ll>vec2;set<ll>s;
        ll q=n-1,k1=0;
        for(ll a=n-1;a>=0;a--)
        {

            if(q>=0&&vec.at(a)<vec1.at(q))
            {
                vec2.push_back(vec1.at(q)-vec.at(a));
                s.insert(vec.at(a));
            }
            if(q>=0&&vec.at(a)>=vec1.at(q))
            {
                ll k=s.size();
                while(k>=s.size())
                {
                    q--;
                    if(q==-1){k1++;break;}
                    s.insert(vec1.at(q));

                }
            }
            if(k1>0)break;

        }
        ll max=vec2.at(0);
        for(ll a=0;a<vec2.size();a++)
        {
            if(vec2.at(a)>max)
            max=vec2.at(a);
        }
        ld a;
        a=log2(max+1);
        cout<<ceil(a)<<fixed<<setprecision(0)<<endl;

    }
}


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

int main(){
	int t;cin>>t;
	while(t--){
		ll n;cin>>n;ll sb[100005];
		for(int i=0;i<n;i++){cin>>sb[i];
		}ll maxn=-1e9+7;ll miin=1e9+7;ll anx=-1e9+7;ll flag=1;
		for(int i=1;i<n;i++){if(sb[i-1]>sb[i]){maxn=sb[i-1];break;
		}
		}
		for(int i=1;i<n;i++){
			if(sb[i]<maxn){flag=0;anx=max(anx,maxn-sb[i]);//cout<<anx<<"\n";
			}
		} ll ans=0;
		while(flag==0&&anx)
	{
		anx>>=1;
		ans++;
	}

    if(flag==1)cout<<"0"<<'\n';
    else
	cout<<ans<<'\n';
	}
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
typedef long long ll;
ll n, a[maxn], c[maxn];
ll high_bit(ll x){
	ll i = 63, e = 1;
	while(!(x & (e << i))) --i;
	return i + 1;
}
void solve(){
	ll i, x, maxi = -10000000000, ans = 0;
	for(i=1;i<=n;++i){
		if(a[i] >= maxi) maxi = a[i];
		else{
			ll temp = high_bit(maxi - a[i]);
			ans = max(ans, temp);
		}
	}
	cout<<ans<<'\n';
}
int main(){
	int t, i, j;
	ios::sync_with_stdio(false);
	cin>>t;
	while(t--){
		cin>>n;
		for(i=1;i<=n;++i) cin>>a[i];
		solve();
	}
	return 0;
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll high_bit(ll x){
	ll i = 63, e = 1;
	while(!(x & (e << i))) --i;
	return i + 1;
}
int main(){
int t;cin>>t;
       while(t--){
       	int n;cin>>n;ll sb[100005];
       	for(int i=0;i<n;i++)cin>>sb[i];
       	ll maxn=-1e9-7;ll anx=-1e9-7;
       	for(int i=0;i<n;i++){
       		if(sb[i]>maxn)maxn=sb[i];
       		else {
       			anx=max(anx,high_bit(maxn-sb[i]));
			   }
		   }
		   if(anx==-1e9-7)cout<<"0"<<"\n";
		   else cout<<anx<<'\n';
	   }
}


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

int main(){
	int t;cin>>t;
	while(t--){
		ll n;cin>>n;ll sb[100005];
		for(int i=0;i<n;i++){cin>>sb[i];
		}ll maxn=-1e9-7;ll miin=1e9+7;ll anx=-1e9-7;ll flag=1;int pos;
		for(int i=1;i<n;i++){if(sb[i-1]>sb[i]){maxn=sb[i-1];break;pos=i-1;
		}
		}
		for(int i=pos+1;i<n;i++){
			if(sb[i]<maxn){flag=0;anx=max(anx,maxn-sb[i]);//cout<<anx<<"\n";
			}
		}
		 ll ans=0;
		while(flag==0&&anx)
	{
		anx>>=1;
		ans++;
	}

    if(flag==1)cout<<"0"<<'\n';
    else
	cout<<ans<<'\n';
	}
}


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

int main(){
	int t;cin>>t;
	while(t--){
		ll n;cin>>n;ll sb[100005];
		for(int i=0;i<n;i++){cin>>sb[i];
		}ll maxn=-1e9-7;ll miin=1e9+7;ll anx=-1e9-7;ll flag=1;
		for(int i=1;i<n;i++){if(sb[i-1]>sb[i]){maxn=sb[i-1];break;
		}
		}
		for(int i=1;i<n;i++){
			if(sb[i]<maxn){flag=0;anx=max(anx,maxn-sb[i]);//cout<<anx<<"\n";
			}
		} ll ans=0;
		while(flag==0&&anx)
	{
		anx>>=1;
		ans++;
	}

    if(flag==1)cout<<"0"<<'\n';
    else
	cout<<ans<<'\n';
	}
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll high_bit(ll x){
	ll i = 63, e = 1;
	while(!(x & (e << i))) --i;
	return i + 1;
}
int main(){	ios::sync_with_stdio(false);
int t;cin>>t;
       while(t--){
       	int n;cin>>n;ll sb[100005];
       	for(int i=0;i<n;i++)cin>>sb[i];
       	ll maxn=-1e9-7;ll anx=-1e9-7;
       	for(int i=0;i<n;i++){
       		if(sb[i]>=maxn)maxn=sb[i];
       		else {
       			anx=max(anx,high_bit(maxn-sb[i]));
			   }
		   }
		   if(anx==-1e9-7)cout<<"0"<<"\n";
		   else cout<<anx<<'\n';
	   }
}


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

int main(){
	int t;cin>>t;
	while(t--){
		ll n;cin>>n;ll sb[100005];
		for(int i=0;i<n;i++){cin>>sb[i];
		}ll maxn=-1e9+7;ll miin=1e9+7;ll anx=-1e9+7;ll flag=1;
		for(int i=1;i<n;i++){
			if(sb[i-1]>sb[i]){flag=0;maxn=max(maxn,sb[i-1]);miin=min(miin,sb[i]);anx=max(anx,maxn-miin);//cout<<anx<<"\n";
			}
		} ll ans=0;
		while(flag==0&&anx)
	{
		anx>>=1;
		ans++;
	}

    if(flag==1)cout<<"0"<<'\n';
    else
	cout<<ans<<'\n';
	}
}


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

int main(){
	int t;cin>>t;
	while(t--){
		ll n;cin>>n;ll sb[100005];
		for(int i=0;i<n;i++){cin>>sb[i];
		}ll maxn=-1e9+7;ll miin=1e9+7;ll anx=-1e9+7;ll flag=1;
		for(int i=1;i<n;i++){
			if(sb[i-1]>=sb[i]){flag=0;maxn=max(maxn,sb[i-1]);miin=min(miin,sb[i]);anx=max(anx,maxn-miin);//cout<<anx<<"\n";
			}
		} ll ans=0;
		while(flag==0&&anx)
	{
		anx>>=1;
		ans++;
	}

    if(flag==1)cout<<"0"<<'\n';
    else
	cout<<ans<<'\n';
	}
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll high_bit(ll x){
	ll i = 63, e = 1;
	while(!(x & (e << i))) --i;
	return i + 1;
}
int main(){
	int t;cin>>t;
	while(t--){
		ll n;cin>>n;ll sb[100005];
		for(int i=0;i<n;i++){cin>>sb[i];
		}ll maxn=-1e9+7;ll miin=1e9+7;ll anx=-1e9+7;ll flag=1;
		for(int i=1;i<n;i++){
			if(sb[i-1]>sb[i]){flag=0;maxn=max(maxn,sb[i-1]);miin=min(miin,sb[i]);anx=max(anx,maxn-miin);//cout<<anx<<"\n";
			}
		}
		ll ans=high_bit(anx);

    if(flag==1)cout<<"0"<<'\n';
    else
	cout<<ans<<'\n';
	}
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	int t;cin>>t;
	while(t--){
		ll n;cin>>n;ll sb[100005];
		for(int i=0;i<n;i++){cin>>sb[i];
		}ll maxn=-1e9-7;ll miin=1e9+7;ll anx=-1e9-7;ll flag=1;int pos;
		for(int i=1;i<n;i++){if(sb[i-1]>sb[i]){maxn=sb[i-1];pos=i-1;break;
		}
		}//cout<<maxn<<" "<<pos<<"\n";
		for(int i=pos+1;i<n;i++){
			if(sb[i]<maxn){flag=0;anx=max(anx,maxn-sb[i]);
			}
		}
		 ll ans=0;if(anx%2!=0){
		 	for(int i=0;i<35;i++){
		 		if(anx<pow(2,i)){anx=pow(2,i); break;
				 }
			 }
		 }
		while(flag==0&&anx)
	{
		anx=anx/2;
		ans++;
	}
    if(flag==1)cout<<"0"<<'\n';
    else
	cout<<ans<<'\n';
	}
}


#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	int t;cin>>t;
	while(t--){
		ll n;cin>>n;ll sb[100005];
		for(int i=0;i<n;i++)cin>>sb[i];
		ll maxn=-1e9-7;ll miin=1e9+7;ll anx=-1e9-7;ll flag=1;ll pos;
		for(int i=1;i<n;i++){
		if(sb[i-1]>sb[i]){
		flag=0;maxn=sb[i-1];pos=i-1;break;
		}
    }//cout<<maxn<<" "<<pos<<"\n";
		if(flag==1)cout<<"0"<<'\n';
		else{
				for(int i=pos+1;i<n;i++){
			if(sb[i]<maxn){anx=max(anx,maxn-sb[i]);
			}
		}
		 ll ans=0;if(anx%2!=0){
		 	for(int i=0;i<35;i++){
		 		if(anx<pow(2,i)){anx=pow(2,i); break;
				 }
			 }
		 }
		while(flag==0&&anx){
		anx=anx/2;
		ans++;
	}
	cout<<ans<<'\n';
		}
	}
}


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define pb push_back
#define mod 1000000007 //998244353
#define all(x) (x).begin(), (x).end()
#define all(x) (x).begin(), (x).end()
#define forf(i,x,y) for(int i=x; i<y; i++)
#define forb(i,x,y) for(int i=x-1;i>=y;i-=2)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define ss second
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=200005, INF=2000000000000000000;

int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }

int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}

int32_t main()
{
    IOS;
    int testcaseva;
    cin>>testcaseva;
    forf(i,0,testcaseva)
    {
        int n;
        cin >> n;
        int ar[n];
        forf(i,0,n)
            cin >> ar[i];
        int ans=0;
        forf(i,1,n){
            if(ar[i]>=ar[i-1])
                continue;
            else {
                int diff=ar[i-1]-ar[i];
                int k = log10(diff)/log10(2);
//                cout << k << endl;

                ar[i]+=pow(2,k);
//                forf(i,0,n)
//                cout << ar[i]<<" ";
//                cout << endl;
                if(k<=ans)
                    ans++;
                else {
                        int p=k+1-ans;
                    ans+=p;
                }

            }
        }
        cout << ans << endl;

    }
}