#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define getmid(l,r) ((l) + ((r) - (l)) / 2) #define MEM(a,b) memset(a,b,sizeof(a)) #define MP(a,b) make_pair(a,b) #define PB push_back typedef long long ll; typedef pair pii; const double eps = 1e-8; const int INF = (1 << 30) - 1; const int maxn = 200010; const int mod = 998244353; int T,n; int A[maxn],pre[maxn],suf[maxn]; int main(){ scanf("%d",&T); while(T--){ scanf("%d",&n); for(int i = 1; i <= n; ++i) scanf("%d",&A[i]); memset(pre,0,sizeof(pre)); memset(suf,0,sizeof(suf)); for(int i = 2; i <= n; ++i){ pre[i] = abs(A[i] - A[i - 1]); pre[i] = max(pre[i],pre[i - 1]); } for(int i = n - 1; i >= 1; --i){ suf[i] = abs(A[i] - A[i + 1]); suf[i] = max(suf[i],suf[i + 1]); } ll ans = 0; for(int i = 1; i <= n; ++i){ if(i == 1) ans += suf[2]; else if(i == n) ans += pre[n - 1]; else{ ans += max(pre[i - 1],max(suf[i + 1],abs(A[i + 1] - A[i - 1]))); //printf("%d %d\n",i,max(pre[i - 1],max(suf[i + 1],abs(A[i + 1] - A[i - 1])))); } } printf("%I64d\n",ans); } return 0; }