#include <bits/stdc++.h>
#include <string.h>

#define fi first
#define se second
#define forn(i,n) for (int i = 0; i < (n); i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define testcase(t) int t;cin>>t;while(t--)
#define mp make_pair
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef pair<int, int> pii;
typedef vector<pii> vpi;

int main()
{
	fast;
	testcase(t)
	{
		int n;
		cin >> n;
		int a[n];
		int count0=0;
		int count1=0;
		int count2=0;
		int ans=0;
		forn(i,n)
		{
			cin >> a[i];
			if(a[i]%3==0)
				count0++;
			if(a[i]%3==1)
				count1++;
			if(a[i]%3==2)
				count2++;
		}

		int x = (count0+count1+count2)/3;
		//cout << count0 << " " << count1 << " " << count2 << endl;
		//cout << x << endl;
		while(count0!=count1 || count1!=count2 || count0!=count2)
		{
			while(count0>x)
			{
				count0--;
				count1++;
				ans++;
			}
			while(count1>x)
			{
				count1--;
				count2++;
				ans++;
			}
			while(count2>x)
			{
				count2--;
				count0++;
				ans++;
			}
			//cout << "Hi"<<endl;
		}
		cout << ans << endl;
	}
return 0;
}