/**************************************************************************\
|---------------------------------INCLUDES---------------------------------|
\**************************************************************************/

#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <bitset>
#include <ctime> 
#include <stack>
#include <typeinfo>
#include <time.h>

using namespace std;

/**************************************************************************\
|----------------------------------DEFINE----------------------------------|
\**************************************************************************/

#define Reverse(v) reverse(v.begin(), v.end())
#define Sort(v) sort(v.begin(), v.end())
#define all_of(v, f) all_of(v.begin(), v.end(), f)
#define apply_to(v, f) transform(v.begin(), v.end(), v.begin(), f) 
#define in int_input()
#define vin(v) v_input(v)
#define safe(v, i, n) (i >= 0 && i < v.size() ? v[i] : n)
#define fori(n) for (ll i = 0; i < n; i++)
#define forj(n) for (ll j = 0; j < n; j++)
#define fork(n) for (ll k = 0; k < n; k++)
#define forij(n, m) fori(n)forj(m)
#define forijk(n, m, k) fori(n)forj(m)fork(k)
#define sum(a) ([&a](){ll sum = 0; for (auto &i : a) sum += i; return sum;})()

/**************************************************************************\
|---------------------------------TYPEDEF----------------------------------|
\**************************************************************************/

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int>pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ull> vul;
typedef vector<pll> vpl;
typedef vector<pii> vpi;
typedef vector<vll> vvl;
typedef vector<vi> vvi;
typedef vector<vul> vvu;
typedef vector<vpl> vvp;
typedef vector<bool> vb;
typedef struct { ll first, second, third; } tll;
typedef vector<tll>vtl;
typedef vector<vvl>vvv;

/**************************************************************************\
|--------------------------------OPERATORS---------------------------------|
\**************************************************************************/

pll operator+ (pll a, pll b) { return { a.first + b.first, a.second + b.second }; }
pll& operator+= (pll& a, pll b) { a = a + b; return a; }

std::istream& operator>> (std::istream& In, vpl& v) {
    for (pll& i : v)
        In >> i.first >> i.second;
    return In;
}
std::istream& operator>> (std::istream& In, vll& vec) {
    for (ll& cur : vec)
        In >> cur;
    return In;
}
std::ostream& operator<< (std::ostream& out, vll& vec) {
    for (ll& cur : vec)
        out << cur << ' ';
    return out;
}

/**************************************************************************\
|-----------------------------------Func-----------------------------------|
\**************************************************************************/

ll int_input() { ll t; cin >> t; return t; }
template<typename TT>
TT v_input(TT v) {
    cin >> v; return v;
}

/**************************************************************************\
|-----------------------------------STRUCTS--------------------------------|
\**************************************************************************/

struct graph {
    vvp g;
    vll v;

    int n, m;

    vll e(int v) {
        vll edges(g[v].size());
        for (int i = 0; i < edges.size(); i++)
            edges[i] = g[v][i].first;
        return edges;
    }

    graph() {}
    graph(int n, int m, bool costs = false, char inp = 'e', bool directed = false, vll* v = nullptr) {
        if (v) this->v = *v;
        else this->v.resize(n);
        this->g.resize(n);
        this->n = n;
        this->m = m;
        if (inp == 'm') {
            for (int i = 0; i < n; i++)
                for (int j = 0; j < n; j++) {
                    int c = in;
                    g[i].push_back({ j, c });
                }
        }
        else if (inp == 'p') {
            for (int i = 1; i < n; i++) {
                int c = in - 1;
                g[c].push_back({ i, 0 });
                if (!directed)
                    g[i].push_back({ c, 0 });
            }
        }
        else if (inp == 'e') {
            for (int i = 0; i < m; i++) {
                int f = in - 1;
                int t = in - 1;
                int c = costs ? in : 0;
                g[f].push_back({ t, c });
                if (!directed)
                    g[t].push_back({ f, c });
            }
        }
    }
};
/**************************************************************************\
|-----------------------------------Main-----------------------------------|
\**************************************************************************/

void solve();

int main() {
    cin.tie(0);
    cout.tie(0);
    ios_base::sync_with_stdio(0);
    
    int t = in;
    while(t--) // Для кодфорсеса с его тестами
        solve();
}

/**************************************************************************\
|----------------------------------SOLVE-----------------------------------|
\**************************************************************************/

void solve() {
    int x = 8, y = 17;
    int res = 0;
    int n = in;
    vll v = vin(vll(n));
    vll c(3, 0);
    fori(n) c[v[i] % 3]++;
    fori(100) {
        if (c[i % 3] > n / 3) {
            res += c[i % 3] - n / 3;
            c[(i + 1) % 3] += c[i % 3] - n / 3;
            c[i % 3] = n / 3;
        }
    }
    cout << res << '\n';
}