#include #include #include #include #include #include #include #include #include using namespace std; typedef long long LL; typedef unsigned long long ULL; const int MaxN = 1e5; int a[MaxN + 5], n, T; struct Point{ int ans, l, r; }seq[MaxN + 5]; bool cmp(Point x, Point y) {return x.ans > y.ans;} int main() { scanf("%d", &T); while(T--) { scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", &a[i]); for(int i = 2; i <= n; i++) { seq[i - 1].ans = abs(a[i] - a[i - 1]); seq[i - 1].l = i - 1; seq[i - 1].r = i; } seq[n].ans = 0; seq[n].l = 0; seq[n].r = 0; sort(seq + 1, seq + n, cmp); LL ans = 0; int p = 1; while(seq[p].l == 1 || seq[p].r == 1) p++; ans += seq[p].ans; for(int i = 2; i <= n - 1; i++) { p = 1; int t = abs(a[i + 1] - a[i - 1]); while(seq[p].l == i || seq[p].r == i) p++; ans += max(t, seq[p].ans); } p = 1; while(seq[p].l == n || seq[p].r == n) p++; ans += seq[p].ans; printf("%I64d\n", ans); } }