#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl "\n"
#define int long long
#define pb push_back
#define getMat(v, n, m, val) vector<vector<int>> v(n,vector<int>(m, val))
#define lb lower_bound
#define ub upper_bound
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define sz(v) (int)v.size()
#define deb(x) cerr << #x ": " << (x) << endl;
#define debv(v) for(int i=0; i<sz(v); i++) cerr << v[i] << " "; cerr << endl;
#define debm(v) for(int i=0; i<sz(v[0]); i++) for(int j=0; j<sz(v[1]); j++){cerr << v[i][j] << " ";} cerr << endl;
#define ar array
using namespace std;
const int mod = 1e9+7;

int32_t main(){
    fastio;
    
    int t; cin >> t;
    while(t--){
        int n; cin >> n;
        vector<int> cnt(3,0); 
        for(int i=0; i<n; i++){
            int x; cin >> x;
            cnt[x%3]++;
        }

        // debv(cnt);
        int f = n/3, ans = 0;
        for(int i=0; i<5; i++){
            if(cnt[i%3] > f){
                cnt[(i+1)%3] += (cnt[i%3]-f);
                ans += (cnt[i%3]-f);
                cnt[i%3] = f;
            }
        }

        cout << ans << endl;
    }
    return 0;
}