#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC optimization("O3")
using namespace std;
const unsigned long long mod = 1000000007;
const long long inf = ((1ll << 31ll) - 1ll);
const long long INF = (((1ll << 59ll) - 1ll) * 2ll) + 1ll;
const long double pi = acos(-1);
const long long MAXN = 1000000;
vector<bool> Criba(MAXN + 1);
vector<long long> primes;
void iniciar_criba() {
  for (long long i = 2; i <= MAXN; i += 2) Criba[i] = 2;
  primes.push_back(2);
  for (long long i = 3; i <= MAXN; i += 2) {
    if (!Criba[i]) {
      primes.push_back(i);
      Criba[i] = i;
      for (long long j = i * i; j <= MAXN; j += (2 * i))
        if (!Criba[j]) Criba[j] = i;
    }
  }
}
bool isprime(long long tupac) { return (Criba[tupac] == tupac); }
long long GCD(long long q, long long r) {
  if (r == 0) return q;
  return GCD(r, q % r);
}
long long LCM(long long q, long long r) { return q * (r / GCD(q, r)); }
long long qpow(long long b, long long e) {
  if (!e) return 1;
  if (e & 1) return qpow(b, e - 1) * b % mod;
  long long pwur = qpow(b, e >> 1);
  return pwur * pwur % mod;
}
long long InverM(long long a, long long b) {
  long long eso = a - (a / b) * b;
  if (eso == 0) return 0;
  long long ans = (1 - b * InverM(b, eso)) / eso;
  if (ans < 0) ans += b;
  return ans;
}
long long t, n, m, k, a, b, t1, t2;
long long fun(long long a, long long b, long long c) {
  long long ans = 0;
  while (c) {
    ans += abs(a - b);
    a--;
    c--;
  }
  return ans;
}
vector<pair<long long, long long> > B;
long long Dp[207][500];
void dp(long long a) {
  for (long long i = 0; i < 2 * n; i++) {
    if (Dp[a - 1][i] == INF) continue;
    for (long long j = B[a].second + i; j <= 2 * n; j++) {
      Dp[a][j] = min(Dp[a - 1][i] + fun(j, B[a].first, B[a].second), Dp[a][j]);
    }
  }
  if (a == B.size() - 1) return;
  dp(a + 1);
}
void problem() {
  cin >> n;
  vector<long long> A;
  for (long long i = 1; i <= n; i++) {
    for (long long j = 0; j <= 2 * n; j++) {
      Dp[i][j] = INF;
    }
  }
  for (long long i = 1; i <= n; i++) {
    long long a;
    cin >> a;
    A.push_back(a);
  }
  sort(A.begin(), A.end());
  long long cont = 1;
  B.resize(0);
  B.push_back({0, 0});
  for (long long i = 1; i < n; i++) {
    if (A[i] != A[i - 1]) {
      B.push_back({A[i - 1], cont});
      cont = 1;
    } else {
      cont++;
    }
  }
  B.push_back({A[n - 1], cont});
  dp(1);
  long long ans = inf;
  for (long long i = 1; i <= 2 * n; i++) {
    long long temp = B.size() - 1;
    if (Dp[temp][i] != -1) ans = min(Dp[temp][i], ans);
  }
  cout << ans;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios::fixed);
  cout.precision(0);
  srand(time(NULL));
  cin >> t;
  while (t--) {
    problem();
    cout << '\n';
  }
  return 0;
}
