#include <iostream>
#include <cmath>
using namespace std;

typedef long long ll;
ll m, n, x = 0, y = 0, q, z, t = 0, a, b, s = 0, c = 0, d = 0, k = 0, i, j, l, r;

int main() {

	cin >> t;
	while (t--) {
		cin >> n; int c[3] = {0};
		for (int i = 0; i < n; ++i) {
			cin >> x; c[x % 3]++;
		}

		d = 0;
		while (c[0] != n/3 || c[1] != n/3 || c[2] != n/3) {
			for (int i = 0; i < 3; ++i) {
				if (c[i] > n/3) {
					d += c[i] - n/3;
					c[(i + 1) % 3] += c[i] - n/3;
					c[i] = n/3;
				}
			}
		}

		cout << d << endl;
	}

	return 0;
}