#include<bits/stdc++.h>
using namespace std;
#define int long long
#define For(i,a,b) for(register int i=a;i<=b;++i)
#define Down(i,a,b) for(register int i=a;i>=b;i--)
#define reg register
inline int min(int x,int y){return x<y?x:y;}
inline int max(int x,int y){return x>y?x:y;}
inline void swap(int &x,int &y){int t=x; x=y; y=t; return ;}
namespace yspm{
	inline int read(){
		int res=0,f=1; char k;
		while(!isdigit(k=getchar())) if(k=='-') f=-1;
		while(isdigit(k)) res=res*10+k-'0',k=getchar();
		return res*f;
	}
	const int N=2e5+10;
	int a[N],c[3],n,ans;
	signed main(){
		int T=read(); while(T--){
			n=read(); ans=0; c[0]=c[1]=c[2]=0; 
			for(reg int i=1;i<=n;++i) a[i]=read(),c[a[i]%3]++;
			int bl=n/3;
			int mx=0,id=-1; for(reg int i=0;i<=2;++i) if(mx<c[i]) mx=c[i],id=i; 
			if(bl==mx){puts("0"); continue;}
			c[(id+1)%3]+=c[id]-bl; ans+=c[id]-bl; 
			id=(id+1)%3; if(c[id]<bl) ans+=2*(bl-c[id]); else ans+=c[id]-bl;
			cout<<ans<<endl;
		}
		return 0;
	}
}
signed main(){return yspm::main();}


