var t,l,i,j,n,max,maxx,max1:longint; a:array[0..100050] of longint; ans:int64; begin readln(t); for l:=1 to t do begin fillchar(a,sizeof(a),0); readln(n); max:=0; maxx:=0; for i:=1 to n do read(a[i]); readln; for i:=2 to n do if (abs(a[i]-a[i-1])>max) then begin max:=abs(a[i]-a[i-1]); maxx:=i-1; end; ans:=0; for i:=1 to n do begin if (i<>1) and (i<>n) and (i<>maxx) and (i<>maxx+1) and (abs(a[i+1]-a[i-1])>max) then ans:=ans+abs(a[i+1]-a[i-1]) else begin if (i<>maxx) and (i<>maxx+1) then ans:=ans+max else begin max1:=0; for j:=1 to i-2 do if (abs(a[j+1]-a[j])>max1) then max1:=abs(a[j+1]-a[j]); if (i>1) and (imax1) then max1:=abs(a[i+1]-a[i-1]); for j:=i+1 to n-1 do if (abs(a[j+1]-a[j])>max1) then max1:=abs(a[j+1]-a[j]); ans:=ans+max1; end; end; end; writeln(ans); end; end.