#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#include<string.h>
#include <iomanip>
#define ll  long long int
int main()
{
    ll cases=1;
    cin>>cases;
    while(cases--)
    {
        ll n;
        cin>>n;
        ll a[n];
        ll c0=0,c1=0,c2=0;
        for(ll i=0;i<n;i++)
        {
            cin>>a[i];
            if(a[i]%3==0)
                c0++;
            else if(a[i]%3==1)
                c1++;
            else
                c2++;
        }
        ll cnt=0;
        ll t=n/3;
        ll p;
        if(c0<t)
        {
            if(c0<t && c2>t)
            {
                p=min(t-c0,c2-t);
                cnt+=p;
                c0+=p;
                c2-=p;
            }
            if(c0<t && c1>t)
            {
                p=min(t-c0,c1-t);
                cnt+=2*p;
                c0+=p;
                c1-=p;
            }
        }
        if(c1<t)
        {
            if(c1<t && c0>t)
            {
                p=min(t-c1,c0-t);
                cnt+=p;
                c1+=p;
                c0-=p;
            }
            if(c1<t && c2>t)
            {
                p=min(t-c1,c2-t);
                cnt+=2*p;
                c1+=p;
                c2-=p;
            }
        }
        if(c2<t)
        {
            if(c2<t && c1>t)
            {
                p=min(t-c2,c1-t);
                cnt+=p;
                c2+=p;
                c1-=p;
            }
            if(c2<t && c0>t)
            {
                p=min(t-c2,c0-t);
                cnt+=2*p;
                c2+=p;
                c0-=p;
            }
        }
        cout<<cnt<<"\n";
    }
    return 0;
}
