#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define mod 1000000007
#define endl '\n'
using namespace std;

typedef  long long LL;
inline LL gcd(LL a, LL b) { return b ? gcd(b, a % b) : a; }
const int N = 500010;

LL n, k;
LL aa[N];

void solve() {
	cin >> n;
	for (int i = 1; i <= n; ++i)cin >> aa[i];

	LL a = 0, b = 0, c = 0;
	for (int i = 1; i <= n; ++i) {
		if (aa[i] % 3 == 0)a++;
		else if (aa[i] % 3 == 1)b++;
		else c++;
	}
	LL res = 0;
	if (a == b && b == c)cout << 0 << endl;
	else {
		LL t = n / 3;
		while (a < t) {
			if (c > t) {
				a++, c--, res += 1;
			}
			else break;
		}
		while (a < t) {
			if (b > t) {
				a++, b--, res += 2;
			}
			else break;
		}
		
		while (b < t) {
			if (a > t) {
				a--, b++, res++;
			}
			else break;
		}
		while (b < t) {
			if (c > t) {
				c--, b++, res+= 2;
			}
			else break;
		}
		while (c < t) {
			if (b > t) {
				b--, c++, res++;
			}
			else break;
		}
		while (c < t) {
			if (a > t) {
				a--, c++, res += 2;
			}
			else break;
		}
		cout << res << endl;
	}
	/*
	LL res = b * 2 + c * 1;
	res = min(a + c, res);
	res = min(a * 2 + b, res);
	*/

}

int main() {
	int t; cin >> t;
	while (t--)
		solve();

	return 0;
}
