#include #include #include #include using namespace std; #define For(i,l,r) for(int i=(l);i<=(r);i++) #define Down(i,r,l) for(int i=(r);i>=(l);i--) #define mset(a,x) memset(a,x,sizeof(a)) int n,a[100005]; void solve() { scanf("%d",&n); For(i,1,n) { scanf("%d",&a[i]); } int k=1,Max=0; For(i,1,n-1) { if(abs(a[i]-a[i+1])>Max) { Max=abs(a[i]-a[i+1]); k=i; } } long long ans=0; if(k==1) { For(i,3,n-1) { ans+=max(Max,abs(a[i+1]-a[i-1])); } ans+=Max; Max=0; For(i,2,n-1) Max=max(Max,abs(a[i+1]-a[i])); ans+=Max; Max=abs(a[1]-a[3]); For(i,3,n-1) Max=max(Max,abs(a[i+1]-a[i])); ans+=Max; } else if(k==n-1) { For(i,2,n-2) { ans+=max(Max,abs(a[i+1]-a[i-1])); } ans+=Max; Max=0; For(i,1,n-2) Max=max(Max,abs(a[i+1]-a[i])); ans+=Max; Max=abs(a[n]-a[n-2]); For(i,1,n-3) Max=max(Max,abs(a[i+1]-a[i])); ans+=Max; } else { For(i,2,n-1) if(i!=k&&i!=k+1) { ans+=max(Max,abs(a[i+1]-a[i-1])); } ans+=Max*2; Max=abs(a[k-1]-a[k+1]); For(i,1,n-1) if(i!=k-1&&i!=k) { Max=max(Max,abs(a[i+1]-a[i])); } ans+=Max; Max=abs(a[k]-a[k+2]); For(i,1,n-1) if(i!=k&&i!=k+1) { Max=max(Max,abs(a[i+1]-a[i])); } ans+=Max; } printf("%I64d\n",ans); } int main() { //freopen("Maple.txt","r",stdin); int T; scanf("%d",&T); while(T--) { solve(); } return 0; }