#define IOS ios::sync_with_stdio(false);
#define rep(i, a, n) for(ll i=a;i<=n;i++)

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define endl "\n"
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e6 + 10;
ll t, n, m, k, ans, cnt, sum, flag;
ll arr[N], brr[N];
char s[N];

int main() {
    IOS;
    cin >> t;
    while (t--) {
        ans = 0;
        ll a=0,b=0,c=0;
        cin >> n;
        rep(i,1,n) {
            cin>>m;
            if(m%3==0) a++;
            else if(m%3==1) b++;
            else c++;
        }
        if(a==b&&b==c) cout<<0<<endl;
        else {
            k=3;
            while(k--){
                if(a>n/3){
                    ans+=a-n/3;
                    b+=a-n/3;
                    a=n/3;
                    if(b>n/3){
                        ans+=b-n/3;
                        c+=b-n/3;
                        b=n/3;
                    }
                }
                else if(b>n/3){
                    ans+=b-n/3;
                    c+=b-n/3;
                    b=n/3;
                    if(c>n/3){
                        ans+=c-n/3;
                        a+=c-n/3;
                        c=n/3;
                    }
                }
                else if(c>n/3){
                    ans+=c-n/3;
                    a+=c-n/3;
                    c=n/3;
                    if(a>n/3){
                        ans+=a-n/3;
                        b+=a-n/3;
                        a=n/3;
                    }
                }
            }
            cout<<ans<<endl;
        }
    }
    return 0;
}