﻿#include<iostream>
#include<cstdio>
using namespace std;
int t,n;
int arr[30005];

char getMax(int a,int b,int c)
{
	if(a == b)
	{
		if(a < c) return 'c';
		else return 'a';
	}else if (b == c)
	{
		if(b < a) return 'a';
		else return 'b';
	}else if(a == c)
	{
		if(a < b) return 'b';
		else return 'c';
	}
	
	if(a > b)
	{
		if(a > c) return 'a';
		else return 'c';
	}else
	{
		if(b > c) return 'b';
		else return 'c';
	}
}

char getMin(int a,int b,int c)
{
	if(a <= b)
	{
		if(c <= a) return 'c';
		else return 'a';
	}else
	{
		if(c <= b) return 'c';
		else return 'b';
	}
}

int main()
{
	scanf("%d",&t);
	while(t--)
	{
		int c0 = 0,c1 = 0,c2 = 0;
		scanf("%d",&n);
		for(int i = 0;i<n;i++) 
		{
			scanf("%d",&arr[i]);
			int remainder = arr[i]%3;
			switch (remainder)
			{
				case 0:
					c0++;
					break;
				case 1:
					c1++;
					break;
				case 2:
					c2++;
					break;
					
			}
		}
		int aver = n/3;
		if(c0==c1&&c1==c2)
		{
			printf("0\n");
			continue;
		}
		int x = 0;
		if(c0 > aver) x++;
		if(c1 > aver) x++;
		if(c2 > aver) x++;
		if(x == 1)
		{
			char max = getMax(c0,c1,c2);
			int ans;
			if(max == 'a')
			ans = 2*c0 + c1 - 3*aver;
			else if(max == 'b')
			ans = 2*c1 + c2 - 3*aver; 
			else
			ans = 2*c2 + c0 - 3*aver;
			printf("%d\n",ans);
		}else if(x == 2)
		{
			char min = getMin(c0,c1,c2);
			int ans;
			if(min == 'a')
			ans = 2*c1 + c2 - 3*aver;
			else if(min == 'b')
			ans = 2*c2 + c0 - 3*aver;
			else
			ans = 2*c0 + c1 - 3*aver;
			printf("%d\n",ans);
		}
	}
	return 0;
}