#include <iostream>
#include <string>
#include <algorithm>
#include<iostream>
#include <math.h>
#include <iomanip>
#include <vector>
#include <iostream>

using namespace std;


void solve(){
 int n; cin >>n;
 int c0=0,c1=0,c2=0;


 int ar[n];
 int v[3]={0};
 for(int i=0; i < n ; i++){
    cin>>ar[i];
    if (ar[i]%3==0)
        c0++;
    else if (ar[i]%3==1)
        c1++;
    else
        c2++;
 }

 int needed= n/3;
 int total=0;

 if (needed == c0 && c0==c1 && c1==c2){
    cout<<0<<endl;
 }else{

  if (c0 < needed){
    if (c2 > needed){
        int c0N = needed-c0;
        int x = c2-needed;

        if (x>c0N){
            c0+=c0N;
            c2-=c0N;
            total+=c0N;
        }else{
            c0+=x;
            c2-=x;
            total+=x;
        }
    }

        if (c1 > needed){
        int c0N = needed-c0;
        int x = c1-needed;

        if (x>c0N){
            c0+=c0N;
            c1-=c0N;
            total+=(c0N*2);
        }else{
            c0+=x;
            c1-=x;
            total+=(x*2);
        }
    }

  }

  // c1

    if (c1 < needed){
    if (c0 > needed){
        int c1N = needed-c1;
        int x = c0-needed;

        if (x>c1N){
            c1+=c1N;
            c0-=c1N;
            total+=c1N;
        }else{
            c1+=x;
            c0-=x;
            total+=x;
        }
    }

        if (c2 > needed){
        int c1N = needed-c1;
        int x = c2-needed;

        if (x>c1N){
            c1+=c1N;
            c2-=c1N;
            total+=(c1N*2);
        }else{
            c1+=x;
            c2-=x;
            total+=(x*2);
        }
    }

  }

 // c2

 if (c2 < needed){
    if (c1 > needed){
        int c2N = needed-c2;
        int x = c1-needed;

        if (x>c2N){
            c2+=c2N;
            c1-=c2N;
            total+=c2N;
        }else{
            c2+=x;
            c1-=x;
            total+=x;
        }
    }

    if (c0 > needed){
        int c2N = needed-c2;
        int x = c0-needed;

        if (x>c2N){
            c2+=c2N;
            c0-=c2N;
            total+=(c2N*2);
        }else{
            c2+=x;
            c0-=x;
            total+=(x*2);
        }
    }

  }

  cout<<total<<endl;

 }

  }

int main() {
 int T; cin>>T;

  while (T--)
    solve();

 }
