#include #include #include using namespace std; typedef long long ll; ll m[100005]; ll Abs(ll a) { return (a >= 0) ? a : -1 * a; } int main() { int T; scanf("%d", &T); while(T--) { ll n, a = 0, p; scanf("%I64d", &n); for(int i = 1; i <= n; ++i) { scanf("%I64d", &m[i]); } for(int i = 2; i <= n; ++i) { if(a < Abs(m[i] - m[i - 1])) { p = i; a = Abs(m[i] - m[i - 1]); } } ll ans = 0, aa = 0; for(int i = 1; i <= n; ++i) { if(i == p || i == p - 1) { aa = 0; for(int j = 1; j <= n; ++j) { if(j == i) { if(j - 1 >= 1 && j + 1 <= n) { aa = max(aa, Abs(m[j + 1] - m[j - 1])); } } if(j != i && j - 1 != i && j - 1 >= 1) aa = max(aa, Abs(m[j] - m[j - 1])); } } else { aa = a; if(i + 1 <= n && i - 1 >= 1) aa = max(a, Abs(m[i + 1] - m[i - 1])); } ans += aa; } printf("%I64d\n", ans); } return 0; }