#include<bits/stdc++.h>
using namespace std;
#define	fo(a,b,c) for(int a=b;a<=c;++a)
#define fr(a,b,c) for(int a=b;a>=c;--a)
#define ll long long
#define pq priority_queue
int t,n,a[30010];
int cnt[3];
bool check()
{
	if(cnt[1]==cnt[2]&&cnt[1]==cnt[0])
		return false;
	return true;	
}
int main()
{
	scanf("%d",&t); 
	while(t--)
	{
		memset(cnt,0,sizeof(cnt));
		int ans=0;
		scanf("%d",&n);
		fo(i,1,n)
			scanf("%d",&a[i]);
		fo(i,1,n)
		{
			if(a[i]%3==0)cnt[0]++;
			else if(a[i]%3==1)cnt[1]++;
			else cnt[2]++;	
		}
		int sum=n/3,i=0;
		while(check())
		{
			int pre=(i+2)%3;
			if(cnt[i]<sum)
			{
				cnt[pre]-=abs(sum-cnt[i]);
				ans+=abs(sum-cnt[i]);
				cnt[i]=sum;
			}
			i=(i+1)%3;
		}	
		printf("%d\n",ans);
	}
    return 0;
}
