#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define eps 1e-9
#define mod 1000000007

using namespace std;

ll arr[3];
int main()
{

    ll t,n,m,f,a,b,c,l,r,q,k,x,y,z,ans,mn,mx,sum=0;
    //ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    cin>>t;

    while(t--)
    {
        cin>>n;
        arr[0]= arr[1]=arr[2]=0;;
        for(int i=0; i<n; i++)
        {
            cin>>x;

            arr[x%3]++;

        }

        x = n/3;
        ans=0;


        while(arr[0]>x && arr[1]<x)
        {
            ans++;
            arr[0]--;
            arr[1]++;
        }

        while(arr[1]>x && arr[2]<x)
        {
            ans++;
            arr[1]--;
            arr[2]++;
        }

        while(arr[2]>x && arr[0]<x)
        {
            ans++;
            arr[2]--;
            arr[0]++;
        }


        while(arr[0]>x && arr[2]<x)
        {
            ans+=2;
            arr[0]--;
            arr[2]++;
        }

        while(arr[1]>x && arr[0]<x)
        {
            ans+=2;
            arr[1]--;
            arr[0]++;
        }

        while(arr[2]>x && arr[1]<x)
        {
            ans+=2;
            arr[2]--;
            arr[1]++;
        }

        cout<<ans<<endl;

    }


}
