#include <bits/stdc++.h>
using namespace std;

int a[30030];
int main() {
    int t; cin >> t;
    while (t--) {
        int n; cin >> n;
        int c[3]{};
        for (int i = 0; i < n; i++) {
            int x; cin >> x;
            c[x % 3]++;
        }
        int k = n / 3;
        int ans = 0;
        // for (int i = 0; i < 3; i++) cout << c[i] << " ";
        // cout << endl;
        
        
        while (!(c[0] == k && c[1] == k && c[2] == k)) {
            for (int i = 0; i < 3; i++) {
                if (c[i] > k) {
                    int moves = c[i] - k;
                    c[i] = k;
                    ans += moves;
                    c[(i + 1) % 3] += moves;
                }
                // cerr << "ans = " << ans << endl;
            }
        }
        // cerr << endl;

        cout << ans << "\n";
    }
}