#include #include #include #include #include #include #include #include #include #include #include #include #include #define PI acos(-1.0) #define ll long long #define INF 0x3f3f3f3f #define eps 1e-6 #define rep(i, a, n) for(int (i) = (a); (i) <= (n); (i)++) #define per(i, n, a) for(int (i) = (n); (i) >= (a); (i)--) #define For(i, a, n) for(int (i) = (a); (i) < (n); (i)++) #define mset(x) memset((x), 0, sizeof((x))) #define meset(x) memset((x), -1, sizeof((x))) #define pb push_back #define mp make_pair #define sf scanf #define pf printf #pragma comment(linker, "/STACK:1024000000,1024000000") #define mod 1000000007 using namespace std; int a[100004]; int main() { int re; sf("%d", &re); while(re--) { int n; sf("%d", &n); int bigest = -1, cnt, index = -1; ll sum = 0; for(int i = 0; i < n; i++) { sf("%d", &a[i]); if(i < 1) continue; if(abs(a[i] - a[i - 1]) > bigest) { index = i; bigest = abs(a[i] - a[i - 1]); } } int tmp = -1; if(index != 0 && index - 1 != 0) { for(int i = 2; i < n; i++) { if(abs(a[i] - a[i - 1]) > tmp) tmp = abs(a[i] - a[i - 1]); } sum += tmp; } tmp = -1; if(index != n - 1 && index - 1 != n - 1) { for(int i = 1; i < n - 1; i++) { if(abs(a[i] - a[i - 1]) > tmp) tmp = abs(a[i] - a[i - 1]); } sum += tmp; } tmp = -1; for(int i = 1; i < n; i++) { if(i == index - 1) continue; else if(i == index) { if(index - 2 >= 0) { tmp = max(tmp, abs(a[i] - a[i - 2])); } else continue; } else tmp = max(tmp, abs(a[i] - a[i - 1])); } sum += tmp; tmp = -1; for(int i = 1; i < n; i++) { if(i == index) continue; else if(i == index + 1) { tmp = max(tmp, abs(a[i] - a[i - 2])); } else tmp = max(tmp, abs(a[i] - a[i - 1])); } sum += tmp; for(int i = 2; i < n; i++) { if(i == index || i == index + 1) continue; if(abs(a[i] - a[i - 2]) > bigest) sum += abs(a[i] - a[i - 2]); else sum += bigest; } pf("%I64d\n", sum); } }