#include #include #include #include #include #include #include #include #define NN 1050 #define MM 50011 #define INF 0x7ffffff #define For(i,n) for(int i=1;i<=n;i++) using namespace std; #define maxn 105000 #define MAXM 50000+10 #define LL long long int N,M,T; LL A[maxn],B[maxn]; LL C[maxn],D[maxn],E[maxn]; LL vis[maxn]; bool cp(LL a,LL b) { return a>b; } int main() { cin>>T; while(T--) { memset(vis,0,sizeof(vis)); scanf("%d",&N); priority_queueQ; For(i,N) { scanf("%lld",&A[i]); } LL G=0; if(N==3) { G+=abs(A[3]-A[2]); G+=abs(A[3]-A[1]); G+=abs(A[2]-A[1]); cout<=MAXN) { G+=m; continue; } LL p=C[i]; LL q=C[i+1]; int u=0; if(Q.top()==p) { E[++u]=Q.top(); Q.pop(); } if(Q.top()==q && Q.top()==MAXN) { E[++u]=Q.top(); Q.pop(); } G+=Q.top(); if(u==2) { Q.push(MAXN); Q.push(MAXN); } if(u==1) { Q.push(MAXN); } } printf("%lld\n",G); } return 0; } /* 5 5 1 7 1 8 5 */