#include #include #include #include #include using namespace std; #define REP(i,n) for(int i(0); i < (n); ++i) #define rep(i,a,b) for(int i(a); i <= (b); ++i) #define dec(i,a,b) for(int i(a); i >= (b); --i) #define for_edge(i,x) for(int i = H[x]; i; i = X[i]) #define LL long long #define ULL unsigned long long #define MP make_pair #define PB push_back #define FI first #define SE second #define INF 1 << 30 const int N = 100000 + 10; const int M = 10000 + 10; const int Q = 1000 + 10; const int A = 30 + 1; int n; int T; int l[N], r[N], a[N]; int main(){ #ifndef ONLINE_JUDGE freopen("test.txt", "r", stdin); freopen("test.out", "w", stdout); #endif scanf("%d", &T); REP(Case, T){ memset(l, 0, sizeof l); memset(r, 0, sizeof r); memset(a, 0, sizeof a); scanf("%d", &n); rep(i, 1, n) scanf("%d", a + i); l[2] = abs(a[2] - a[1]); rep(i, 3, n) l[i] = max(abs(a[i] - a[i - 1]), l[i - 1]); r[n - 1] = abs(a[n] - a[n - 1]); dec(i, n - 2, 1) r[i] = max(abs(a[i] - a[i + 1]), r[i + 1]); /*rep(i, 2, n) printf("%d ", l[i]); puts(""); rep(i, 1, n - 1) printf("%d ", r[i]); puts("");*/ LL ans = r[2] + l[n - 1]; rep(i, 2, n - 1) ans += max(max(l[i - 1], r[i + 1]), abs(a[i + 1] - a[i - 1])); printf("%I64d\n", ans); } return 0; }