#include #include #include #include #include #include using namespace std; int n,N; int rmq[400000],a[100100]; void update(int k,int x) { k+=N-1; rmq[k]=x; while(k>0) { k=(k-1)/2; rmq[k]=max(rmq[k*2+1],rmq[k*2+2]); } } int main() { int T; while(scanf("%d",&T)==1) { while(T--) { long long sum=0; memset(rmq,0,sizeof(rmq)); scanf("%d",&n); N=1; while(N