typedef long long int ll;
#define fio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#include<bits/stdc++.h>
using namespace std;
int main()
{
    fio;
    int t; cin>>t;
    while(t--)
    {
        int n; cin>>n; int no;
        int c2=0, c1=0, c0=0;
        for(int i=0; i<n; ++i)
        {
            cin>>no;
            if(no%3==2)
                c2++;
            else if(no%3==1)
                c1++;
            else
                c0++;
        }
        int r[3];
        r[0]=c0; r[1]=c1; r[2]=c2;
        int p=n/3;
        ll moves=0;
        int max_iteration=2;
        while(max_iteration--)
        {
            for(int i=0; i<3; ++i)
            {
                if(r[i] >p)
                {
                    moves+=r[i]-p;
                    r[(i+1)%3]+=r[i]-p;
                    r[i]=p;
                }
            }
        }
        cout<<moves<<"\n";
    }
    return 0;
}
