#include <bits/stdc++.h>
using namespace std;

#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1)
{
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args)
{
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define FASTER                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);                    \
  cout.tie(NULL);

using ll = long long;

int main()
{
  FASTER;
  int t;
  cin >> t;
  while (t--)
  {
    int n;
    cin >> n;
    vector<ll> A(n);
    for (auto &x : A)
      cin >> x;
    ll ans = 0;
    for (int i = 1; i < n; i++)
      ans += abs(A[i] - A[i - 1]);
    ll saving = 0;
    for (int i = 0; i < n; i++)
    {
      if (i == 0)
        saving = max(saving, abs(A[1] - A[0]));
      else if (i == n - 1)
        saving = max(saving, abs(A[n - 1] - A[n - 2]));
      else
      {

        ll b = A[i];
        ll a = A[i - 1];
        ll c = A[i + 1];
        saving = max(saving, (abs(a - b) + abs(c - b)) - abs(c - a));
      }
    }
    cout << ans - saving << endl;
  }
  return 0;
}
