#include <iostream>

using namespace std;

const int N = 3e4 + 10;

int t;

int main()
{
	cin >> t;
	while(t --)
	{
		int n,c[3] = {0};
		int a[N];
		cin >> n;
		
		for(int i = 1;i <= n;i ++)
		{
			cin >> a[i];
			c[a[i] % 3] ++;
		}
	//	cout << c[0] << c[1] << c[2] << endl;
		int x = n / 3;
		int cnt = 0;
		while(c[0] != x || c[1] != x || c[2] != x)
		{
			
			if(c[0] > x)
			{
				int y = c[0] - x;
				cnt += y;
				c[0] = x;
				c[1] += y;
			}
			
			if(c[1] > x)
			{
				int y = c[1] - x;
				cnt += y;
				c[1] = x;
				c[2] += y;
			}
			
			if(c[2] > x)
			{
				int y = c[2] - x;
				cnt += y;
				c[2] = x;
				c[0] += y;
			}
		//	cout << cnt << endl;
		}
		
		cout << cnt << endl;
	}
}
				    	   	 		 	  					 	 		