#include #include #include #include #include #include #include #include #include #include #include #include #define m_p make_pair #define p_b push_bakc #define fi first #define se second #define LL long long using namespace std; const int maxn = 100010; LL a[maxn]; LL l[maxn],r[maxn]; int main() { //freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout); int tt; scanf("%d",&tt); while(tt--) { int n; scanf("%d",&n); for (int i=1; i<=n; i++) scanf("%I64d",&a[i]); LL Max=abs(a[1]-a[2]); memset(l,0,sizeof(l)); memset(r,0,sizeof(r)); for (int i=2; i1; i--) { r[i-1]=Max; Max=max(Max,abs(a[i]-a[i-1])); } LL sum=r[1]+l[n]; for (int i=2; i<=n-1; i++) sum+=max(abs(a[i-1]-a[i+1]),max(l[i],r[i])); printf("%I64d\n",sum); } return 0; }