#include<bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define sz(a) ((a).size())
#define pb push_back
#define pf push_front
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define mem(a,val) memset(a,val,sizeof(a))
#define forn(i,a,n) for(i = a; i < (n); i++)
#define maxn 1000000007
#define ll long long
#define endl '\n'

int main()
{
    ll q=1,i,j,test,k=1;
    cin>>q;
	forn(test,1,q+1)
	{
	    int n,k,ans=0;
	    cin>>n;
	    vector< int >m(3,0);
	    forn(i,0,n)
	    {
	        cin>>k;
	        k%=3;
	        m[k]++;
	    }
	    if(m[0]>n/3)
	    {
	        ans+=m[0]-n/3;
	        m[1]+=m[0]-n/3;
	        m[0]=n/3;
	    }
	    if(m[1]>n/3)
	    {
	        ans+=m[1]-n/3;
	        m[2]+=m[1]-n/3;
	        m[1]=n/3;
	    }
	    if(m[2]>n/3)
	    {
	        ans+=m[2]-n/3;
	        m[0]+=m[2]-n/3;
	        m[2]=n/3;
	    }
	    if(m[0]>n/3)
	    {
	        ans+=m[0]-n/3;
	        m[1]+=m[0]-n/3;
	        m[0]=n/3;
	    }
	    
	    cout<<ans<<endl;
	    
	}
}