#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>
constexpr auto PI = 3.141592653589793;
using namespace std;
int main() {
	int t, n, a[30000],x,m,c[3];
	cin >> t;
	while (t--) {
		x = 0;
		c[0] = 0;
		c[2] = 0;
		c[1] = 0;
		cin >> n;
		for (int i = 0;i < n;i++) {
			cin >> a[i];
			c[a[i] % 3]++;
		}
		n /= 3;
		if (c[0] != c[1] || c[1] != c[2]) {
			for (int i = 0;i < 3;i++) {
				if (c[i] > n) {
					for (int k = 1;k < 3 && c[i] > n;k++) {
						if (c[(i + k) % 3] < n) {
							if (abs(n - c[(i + k) % 3]) > abs(n - c[i])) {
								x += abs((n - c[i]) * k);
								c[(i + k) % 3] += n - c[i];
								c[i] = n;
							}
							else {
								x +=abs( (n - c[(i + k) % 3]) * k);
								c[i] -= n - c[(i + k) % 3];
								c[(i + k) % 3] = n;
							}
						}
					}
				}
			}
		}
		cout << x << endl;
	}
	return 0;
}