#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include /*______________#########____________________*\ ______________############_____________________ ______________#############____________________ _____________##__###########___________________ ____________###__######_#####__________________ ____________###_#######___####_________________ ___________###__##########_####________________ __________####__###########_####_______________ ________#####___###########__#####_____________ _______######___###_########___#####___________ _______#####___###___########___######_________ ______######___###__###########___######_______ _____######___####_##############__######______ ____#######__#####################_#######_____ ____#######__##############################____ ___#######__######_#################_#######___ ___#######__######_######_#########___######___ ___#######____##__######___######_____######___ ___#######________######____#####_____#####____ ____######________#####_____#####_____####_____ _____#####________####______#####_____###______ ______#####______;###________###______#________ \*______##_______####________####____________*/ using namespace std; long long abss(long long a) { if (a < 0) { return -1 * a; } else { return a; } } int cmp(long long a, long long b) { return a>b; } long long data[100005]; long long dats[100005]; int main() { int T; scanf("%I64d", &T); while (T--) { long long ans = 0; long long n; memset(dats, 0, sizeof(dats)); scanf("%I64d", &n); for (int i = 0; i < n; i++) { scanf("%I64d", &data[i]); } long long maxs = 0; for (int i = 1; i < n - 1; i++) { maxs = max(maxs, abss(data[i] - data[i + 1])); } ans += maxs; maxs = 0; for (int i = 0; i < n - 2; i++) { maxs = max(maxs, abss(data[i] - data[i + 1])); } ans += maxs; maxs = 0; for (int i = 0; i < n - 1; i++) { dats[i] = abss(data[i] - data[i + 1]); } sort(dats, dats + n - 1, cmp); long long t1, t2; for (int i = 1; i < n - 1; i++) { maxs = 0; t1 = min(abss(data[i] - data[i + 1]), abss(data[i - 1] - data[i])); t2 = max(abss(data[i] - data[i + 1]), abss(data[i - 1] - data[i])); if (t1 != dats[0] && t2!= dats[0]) { ans += max(dats[0], abss(data[i - 1] - data[i + 1])); } else if (t1 != dats[1] && t2 != dats[1]) { ans += max(dats[1], abss(data[i - 1] - data[i + 1])); } else { ans += max(dats[2], abss(data[i - 1] - data[i + 1])); } } printf("%I64d\n", ans); } }