#pragma comment(linker, "/STACK:102400000,102400000") #include #include #include #include #include #include #include #include #include #include using namespace std; const double eps = 1e-6; const double pi = acos(-1.0); const int INF = 1e9; const int MOD = 1e9+7; #define ll long long #define CL(a,b) memset(a,b,sizeof(a)) #define lson (i<<1) #define rson ((i<<1)|1) #define N 100010 int gcd(int a,int b){return b?gcd(b,a%b):a;} int n,m; int a[N]; int aa,bb,cc; int main() { int T; int l,r; scanf("%d",&T); while(T--) { scanf("%d",&n); ll sum = 0; aa=bb=cc=0; int p1=-1,p2=-1; for(int i=0; i0) { int d = abs(a[i]-a[i-1]); if(d > aa) { cc=bb; bb=aa, p2=p1; aa = d, p1 = i; } else if(d > bb) cc=bb,bb = d, p2 = i; else if(d > cc) cc = d; } } if(p1 == 1) sum += bb; else sum += aa; if(p1 == n-1) sum += bb; else sum += aa; for(int i=2; i