#include <bits/stdc++.h>
#define fo(i,n) for(long i=0;i<n;i++)
#define rfo(i,n,j) for(long i=n;i>=j;i--)
#define st(a,n)  sort(a,a+n)
#define pi 1000000007
using namespace std;

bool ch(long long a)
  {
      if(a==2|| a==3)
        return true;
      if(a%2 ==0)
        return false;
              
     for(long long i=3;i*i<=a;i+=2)
        {
            if(a%i ==0)
               return false ;
        }
     return true;
       
  }

int main ()
{
  ios_base::sync_with_stdio (false);
  cin.tie (NULL);
  cout.tie (NULL);

  long t;
  cin>>t;
  while(t>0)
    {
        long n;
        cin>>n;
        long a[n];
        long hash[3] ={0};
        fo(i,n)
          {
              cin>>a[i];
              hash[(a[i]%3)]++;
          }
        long ma = max(hash[0],max(hash[1],hash[2]));
        long ans =0;
        if(hash[0]>(n/3))
          {
            if(hash[1]<(n/3))
              { 
                long mem = hash[1];  
                hash[1] = hash[1] + min(((n/3)-hash[1]),(hash[0]-(n/3)))  ;
                hash[0] = hash[0] - (hash[1]-mem);
                ans = ans + (hash[1]-mem);
              }
            
          } 
        if(hash[1]>(n/3))
          {
            if(hash[2]<(n/3))
              { 
                long mem = hash[2];  
                hash[2] = hash[2] + min(((n/3)-hash[2]),(hash[1]-(n/3)))  ;
                hash[1] = hash[1] - (hash[2]-mem);
                ans = ans + (hash[2]-mem);
              }
            
          } 
        if(hash[2]>(n/3))
          {
            if(hash[0]<(n/3))
              { 
                long mem = hash[0];  
                hash[0] = hash[0] + min(((n/3)-hash[0]),(hash[2]-(n/3)))  ;
                hash[2] = hash[2] - (hash[0]-mem);
                ans = ans + (hash[0]-mem);
              }
            
          } 
        if(hash[0]>(n/3))
          {
            if(hash[2]<(n/3))
              {
                long mem = hash[2];
                hash[2] = n/3;
                hash[0] = n/3;
                ans = ans + ((hash[2]-mem)*2); 
              }
          }
        
        if(hash[1]>(n/3))
          {
            if(hash[0]<(n/3))
              {
                long mem = hash[0];
                hash[1] = n/3;
                hash[0] = n/3;
                ans = ans + ((hash[0]-mem)*2); 
              }
          }
        if(hash[2]>(n/3))
          {
            if(hash[1]<(n/3))
              {
                long mem = hash[1];
                hash[2] = n/3;
                hash[1] = n/3;
                ans = ans + ((hash[1]-mem)*2); 
              }
          }
        cout<<ans<<endl;
        t--;
    }
    
    
  
}