#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <math.h>
using namespace std;
const int maxn=3e4+20;
int t,n,a[maxn];
int main()
{
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d",&n);
        int ave=n/3,c0=0,c1=0,c2=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            if(a[i]%3==0) c0++;
            else if(a[i]%3==1) c1++;
            else c2++;
        }
        int ans=0;
        if(c0==c1&&c1==c2) printf("%d\n",ans);
        else
        {
            int k=3;
            while(k--)
            {
                if(c0>ave)
                {
                    ans+=c0-ave;
                    c1+=c0-ave;
                    c0=ave;
                    if(c1>ave)
                    {
                        ans+=c1-ave;
                        c2+=c1-ave;
                        c1=ave;
                    }
                }
                else if(c1>ave)
                {
                    ans+=c1-ave;
                    c2+=c1-ave;
                    c1=ave;
                    if(c2>ave)
                    {
                        ans+=c2-ave;
                        c0+=c2-ave;
                        c2=ave;
                    }
                }
                else if(c2>ave)
                {
                    ans+=c2-ave;
                    c0+=c2-ave;
                    c2=ave;
                    if(c0>ave)
                    {
                        ans+=c0-ave;
                        c1+=c0-ave;
                        c0=ave;
                    }
                }
            }
        printf("%d\n",ans);
        }

    }
    return 0;
}

	  	 	   				 			  			  			 	