#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const int mod = 1e9 + 7;
long long a[505][505];
long long vis[maxn];
long long t[maxn];
struct edge {
  long long nex, t, v, c;
};
struct MCMF {
  edge e[maxn];
  long long maxflow, mincost;
  long long h[maxn], cnt, s, t, N;
  long long dis[maxn], pre[maxn], incf[maxn];
  bool vis[maxn];
  void add_path(long long f, long long t, long long v, long long c) {
    e[++cnt] = edge{h[f], t, v, c}, h[f] = cnt;
  }
  void add_flow(long long f, long long t, long long v, long long c) {
    add_path(f, t, v, c);
    add_path(t, f, 0, -c);
  }
  bool spfa() {
    for (int i = 0; i <= N; i++) dis[i] = 0x3f3f3f3f3f, vis[i] = false;
    queue<int> q;
    q.push(s), dis[s] = 0, incf[s] = 0x3f3f3f3f3f, incf[t] = 0, vis[s] = true;
    while (q.size()) {
      int u = q.front();
      q.pop();
      vis[u] = 0;
      for (int i = h[u]; i; i = e[i].nex) {
        const long long &v = e[i].t, &w = e[i].v, &c = e[i].c;
        if (!w || dis[v] <= dis[u] + c) continue;
        dis[v] = dis[u] + c, incf[v] = min(w, incf[u]), pre[v] = i;
        if (!vis[v]) q.push(v), vis[v] = 1;
      }
    }
    return incf[t];
  }
  void update() {
    maxflow += incf[t];
    for (int u = t; u != s; u = e[pre[u] ^ 1].t) {
      e[pre[u]].v -= incf[t], e[pre[u] ^ 1].v += incf[t];
      mincost += incf[t] * e[pre[u]].c;
    }
  }
  void work() {
    maxflow = mincost = 0;
    while (spfa()) update();
  }
} mcmf;
void solve() {
  int n;
  cin >> n;
  memset(mcmf.h, 0, sizeof(mcmf.h));
  mcmf.cnt = 1, mcmf.N = 805, mcmf.s = 0, mcmf.t = 233;
  for (int i = 1; i <= n; i++) {
    int temp;
    cin >> temp;
    mcmf.add_flow(0, i, 1, 0);
    for (int j = 1; j <= 400; j++) {
      mcmf.add_flow(i, 400 + j, 1, abs(temp - j));
    }
  }
  for (int j = 1; j <= 400; j++) mcmf.add_flow(400 + j, 233, 1, 0);
  mcmf.work();
  cout << mcmf.mincost << endl;
}
int main() {
  int T;
  for (cin >> T; T; T--) {
    solve();
  }
}
