#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 1000 + 10;
struct Edge {
  int u, v, c, f, cost;
  Edge(int u, int v, int c, int f, int cost)
      : u(u), v(v), c(c), f(f), cost(cost) {}
};
vector<Edge> e;
vector<int> G[maxn];
int a[maxn];
int p[maxn];
int d[maxn];
int inq[maxn];
int n, m;
void init(int n) {
  for (int i = 0; i <= n; i++) G[i].clear();
  e.clear();
}
void addEdge(int u, int v, int c, int cost) {
  e.push_back(Edge(u, v, c, 0, cost));
  e.push_back(Edge(v, u, 0, 0, -cost));
  int m = e.size();
  G[u].push_back(m - 2);
  G[v].push_back(m - 1);
}
bool bellman(int s, int t, int& flow, long long& cost) {
  for (int i = 0; i <= t + 1; i++) d[i] = INF;
  memset(inq, 0, sizeof(inq));
  d[s] = 0;
  inq[s] = 1;
  p[s] = 0;
  a[s] = INF;
  queue<int> q;
  q.push(s);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    inq[u] = 0;
    for (int i = 0; i < G[u].size(); i++) {
      Edge& now = e[G[u][i]];
      int v = now.v;
      if (now.c > now.f && d[v] > d[u] + now.cost) {
        d[v] = d[u] + now.cost;
        p[v] = G[u][i];
        a[v] = min(a[u], now.c - now.f);
        if (!inq[v]) {
          q.push(v);
          inq[v] = 1;
        }
      }
    }
  }
  if (d[t] == INF) return false;
  flow += a[t];
  cost += (long long)d[t] * (long long)a[t];
  for (int u = t; u != s; u = e[p[u]].u) {
    e[p[u]].f += a[t];
    e[p[u] ^ 1].f -= a[t];
  }
  return true;
}
int MincostMaxflow(int s, int t, long long& cost) {
  cost = 0;
  int flow = 0;
  while (bellman(s, t, flow, cost))
    ;
  return flow;
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    init(3 * n + 10);
    int s = 0, t = 3 * n + 1;
    for (int i = 1; i <= 2 * n; i++) addEdge(s, i, 1, 0);
    for (int i = 1, x; i <= n; i++) {
      scanf("%d", &x);
      for (int j = 1; j <= 2 * n; j++) {
        addEdge(j, i + 2 * n, 1, abs(j - x));
      }
      addEdge(i + 2 * n, t, 1, 0);
    }
    long long cost = 0;
    MincostMaxflow(s, t, cost);
    printf("%lld\n", cost);
  }
}
