#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{

 ll t,n,c0,c1,c2,x;
 cin>>t;
 while(t--)
 {
    c0=0,c1=0,c2=0;
    cin>>n;
    while(n--)
    {
        cin>>x;
        if(x%3==1)c1++;
        else if(x%3==2)c2++;
        else c0++;
    }
    cout<<max(c0-c2,max(c2-c1,c1-c0))<<endl;
 }
}


