#include <bits/stdc++.h>
using namespace std;
const int MAXX=3*1e4+10;
int a[MAXX],b[5];
int main()
{
    int t; cin>>t;
    while(t--){
    	int n; cin>>n;
    	for(int i=0;i<n;i++){
    		cin>>a[i];
    		b[a[i]%3]++;
		}
		int ans=0;
		n=n/3;
		b[0]-=n; b[1]-=n; b[2]-=n;
		if(b[0]>0) b[1]+=b[0],ans+=b[0],b[0]=0; //cout<<ans<<endl;
		if(b[1]>0) b[2]+=b[1],ans+=b[1],b[1]=0; //cout<<ans<<endl;
		if(b[2]>0) b[0]+=b[2],ans+=b[2],b[2]=0; //cout<<ans<<endl;
		if(b[0]>0) b[1]+=b[0],ans+=b[0],b[0]=0; //cout<<ans<<endl;
		if(b[1]>0) b[2]+=b[1],ans+=b[1],b[1]=0; //cout<<ans<<endl;
		cout<<ans<<endl;
		b[0]=b[1]=b[2]=0;
	}
    return 0;
}