#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int 
#define loop(x,n) for(int x = 0;x< n;x++)
#define pi pair<ll,ll>
#define v vector<ll>
#define vp vector<pi>
#define s set<ll>
#define sp set<pi>
#define m map<ll,ll>
#define gcd(x,y) __gcd(x,y)
#define setbits(x) __builtin_popcount(x)
 
ll t,n,i,ans,smaller,larger,temp,j;
int main() {
	// your code goes here
// 	ios_base::sync_with_stdio(false);
// 	cin.tie(NULL);
// 	cout.tie(NULL);
//     #ifndef ONLINE_JUDGE
//     	freopen("input.txt", "r", stdin);
//     	freopen("Output.txt", "w", stdout);
//     #endif
    cin>>t;
    while(t--)
    {
        cin>>n;
        ll a[n];
        loop(i,n){
            cin>>a[i];
        }
        ans=0;
        m remainder;
        loop(i,n)
        {
            remainder[a[i]%3]++;
        }
        while(remainder[0]!=n/3 || remainder[1]!=n/3 || remainder[2]!=n/3)
        {
            for(i=0;i<3;i++)
            {
                if(remainder[i]>n/3)
                {
                    ans++;
                    remainder[i]--;
                    remainder[(i+1)%3]++;
                }
            }
        }
        
        cout<<ans<<"\n";
    }
    
	
	return 0;
}