#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

inline int read(){
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    return x*f;
}
const int maxn = 3e4 + 9; 
int t;
int a[3];
int solve(){
	int l = a[0], m = a[1], r = a[2];
	int avg = (l + m + r) / 3;
	//printf("avg: %d\n", avg);
	int ans = 0;
	if (l < avg){
		if (r > avg){
			if (m > avg){
				ans += (m - avg) * 2 + r - avg;
				return ans;
			}
			else if (m < avg){
				ans += avg - l + (avg - m) * 2;
				return ans;
			}
			else{
				ans += avg - l;
				return ans;
			}
		}
		else if (r < avg){
			ans += (avg - l) * 2 + avg - r;
			return ans;
		}
		else{
			ans += (avg - l) * 2;
			return ans;
		}
	}
	else if (l == avg){
		if (m == avg){
			return ans;
		}
		else if (m < avg){
			ans += (avg - m) * 2;
			return ans;
		}
		else{
			ans += m - avg;
			return ans;
		}
	}
	else{
		if (m < avg){
			if (r > avg){
				ans += (r - avg) * 2 + l - avg;
				return ans;
			}
			else if (r < avg){
				ans += (avg - r) * 2 + avg - m;
				return ans;
			}
			else{
				ans += avg - m;
				return ans;
			}
		}
		else if (m > avg){
			ans += (l - avg) * 2 + m - avg;
			return ans;
		}
		else{
			ans = (l - avg) * 2;
			return ans;
		}
	}
	return ans;
}
int main(){
    t = read();
    while(t--){
    	int n = read();
    	int m;
    	a[0] = a[1] = a[2] = 0;
    	for (int i = 1; i <= n; i++){
    		m = read();
    		a[m % 3]++;
		}
		//sort(a, a + 3);
		int ans = solve();
		printf("%d\n", ans);
	}
	return 0;
}
