#include <bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>


#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

using namespace std;
#define endl '\n'
#define cendl cout << endl

#define ll long long
#define ld long double
#define ull unsigned long long

#define ic(x) static_cast<int>(x)
#define dc(x) static_cast<double>(x)

#define test_cases       long long t; cin >> t; while(t--)
#define forn(i, n)       for (long long i = 0; i < n; ++i)
#define fork(k,n, i)     for (auto i = k; i <= n; ++i)
#define forki(k,n,i, a)  for (auto i = k; i <= n; i+=a)
#define forkr(k,n,i)     for (auto i = k-1; i >= n; --i)
#define forv(vec)        for (auto it : vec) cout << it << ' ';
#define cinArray(ar)     for (auto &i : ar) cin >> i;

#define deb(x) cout << #x << " = " << x << "\n";
#define deb2(x, y) cout << #x << " = " << x << ", " << #y << " = " << y << endl

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) x.begin(), x.end()

#define MOD 1000000007 // MODulo 1e9 + 7

typedef pair<int, int>  pii;
typedef pair<long long, long long>     pl;
typedef vector<int>      vi;
typedef vector<long long>       vl;
typedef vector<pii>    vpii;
typedef vector<pl>      vpl;
typedef vector<vi>      vvi;
typedef vector<vl>      vvl;
typedef unordered_set<int> usint;
typedef unordered_map<int, int> umap;
typedef priority_queue<int> pq;

/*======= User-defined Function ======*/

/*====================================*/
int32_t main() {
  /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
  #endif*/


  test_cases{
    ll n; cin >> n;

    ll zero{}, one{}, two{};
    for (ll i = 0; i < n; ++i)  {
      ll x; cin >> x;

      if (x % 3 == 0) ++zero;
      else if (x % 3 == 1) ++one;
      else ++two;

    }


    ll max_ap = n / 3;
    ll result = 0;

    while (zero != max_ap or one != max_ap or two != max_ap) {
      if (zero < max_ap) {
        if (two > max_ap) {
          ll need = max_ap - zero;
          // min(need, two);
          ll possible = min(need, two);
          zero += possible;
          two -= possible;
          result += possible;
        }
        if (zero < max_ap) {
          ll need = max_ap - zero;
          // min(need, one);
          ll possible = min(need, one);
          zero += possible;
          one -= possible;
          result += (possible * 2);
        }
      }


      if (one < max_ap) { // check if one needs to be filled up
        if (zero > max_ap) { // if we can pass zeroes to one then do it
          ll need = max_ap - one; // calculate how much we need to take
          // min(need, one);
          ll possible = min(need, zero); //calc how much we can take
          one += possible; // add as much as we can to one
          zero -= possible; // subtract it from zero
          result += possible; // increase the result
        }
        if (one < max_ap) { // if one is still not filled up then take twos
          ll need = max_ap - one; //check how much we need
          // min(need, two);
          ll possible = min(need, two); // how much we can take
          one += possible; // increase ones
          two -= possible; // subtract from two
          result += (possible * 2); // multiply the poss by 2 bcs we need two moves to get one
        }
      }


      if (two < max_ap) { // check if two needs to be filled up
        if (one > max_ap) { // if we can pass ones to zero then do it
          ll need = max_ap - two; // calculate how much we need to take
          // min(need, one);
          ll possible = min(need, one); //calc how much we can take
          two += possible; // add as much as we can to one
          one -= possible; // subtract it from zero
          result += possible; // increase the result
        }
        if (two < max_ap) { // if two is still not filled up then take zeroes
          ll need = max_ap - two; //check how much we need
          // min(need, zero);
          ll possible = min(need, zero); // how much we can take
          two += possible; // increase twos
          zero -= possible; // subtract from two
          result += (possible * 2); // multiply the poss by 2 bcs we need two moves to get one
        }
      }
    }
    cout << result;

    cout << endl;
  }



  return 0;
}

/* TO DO:

N = 4
1 2 3 4 5
2 3 4 5 1

A. Almost Prime
The shortest statement
Written by Zula - acmASCIS

*/

/*
stuff you should look for:
• int overflow, array bounds
• special cases (n=1?)
• do smth instead of nothing and stay organized
• WRITE STUFF DOWN
• DON'T GET STUCK ON ONE APPROACH
* /
/*

• Number of digits in N = floor(log10(N)) + 1;
• Sum of natural numbs:  n * (n + 1) / 2;
• if (num & 1) cout << "ODD";
• n = n << 1;   // Multiply n with 2
• n = n >> 1;   // Divide n by 2
• double logxY = log(y) / log(x); (int might cause erros!)
• Check if a^b > c^d  => (b * log(a) > d * log(c) ? "YES" : "NO"); // also possible to use log10

arbitrary order = dowolna kolejnosc

*/