#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <vector>
#include <cstring>
#include <iomanip>
#include <stack>
#include <queue>
#include <deque>
#include <string>
#include <fstream>
#include <cctype>

using namespace std;

#define re return
#define sz(n) (int)(n.size())
#define all(x) x.begin(),x.end()
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long> vll;
typedef vector<string> vs;
typedef pair<int, int> pii;

typedef long long int i;
const long mod = 1e9 + 7;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin >> n;
        vi a(n);
        int c0 = 0, c1 = 0, c2 = 0;
        for (auto &i: a) {
            cin >> i;
            if (i % 3 == 0)
                ++c0;
            else if (i % 3 == 1)
                ++c1;
            else if (i % 3 == 2)
                ++c2;
        }
        int norm = n / 3;
        int kol = 0;
        if (c0 == c1 && c1 == c2){
            cout << "0\n";
            continue;
        }
        while (c0 != c1 || c1 != c2) {
            if (c0 > norm) c0--, c1++, kol++;
            if (c1 > norm) c1--, c2++, kol++;
            if (c2 > norm) c2--, c0++, kol++;
        }
        cout << kol << '\n';
    }
}