#include #include #include #include #include #include #define LL long long #define pb push_back using namespace std; const int N = 100010; int a[N], t[N]; bool del[5]; int main() { int T; scanf("%d", &T); while (T--) { int n; scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); if (i > 1) t[i - 2] = abs(a[i] - a[i - 1]); } sort(t, t + n - 1, greater()); if (n == 3) t[2] = 0; LL ans = 0, maxx; for (int i = 1; i <= n; ++i) { del[0] = del[1] = del[2] = 0; if (i > 1) { for (int j = 0; j < 3; ++j) if (!del[j] && abs(a[i] - a[i - 1]) == t[j]) { del[j] = 1; break; } } if (i < n) { for (int j = 0; j < 3; ++j) if (!del[j] && abs(a[i + 1] - a[i]) == t[j]) { del[j] = 1; break; } } if (i > 1 && i < n) maxx = abs(a[i + 1] - a[i - 1]); else maxx = 0; for (int j = 0; j < 3; ++j) if (!del[j]) maxx = max(maxx, (LL)t[j]); ans += maxx; } printf("%I64d\n", ans); } return 0; }