#include<bits/stdc++.h>
using namespace std;
#define _rep(i, x, y) for(int i = (int)x; i < (int)y; ++i)
#define _dep(i,x,y) for(int i = (int)x; i > (int)y; i--)
#define PII pair<int,int>
#define eb emplace_back
#define pb push_back
#define fi first
#define se second
#define PQ priority_queue
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VII;
typedef vector<ll> VL;
typedef vector<vector<ll>> VLL;
constexpr int mod = 1e9 + 7;
constexpr int KINF = 0x3f3f3f3f;
constexpr double eps = 1e-7;
int main(){
	ios::sync_with_stdio(false); cin.tie(0);
	int _;
	cin >> _;
	while(_--){
		int n;
		cin >> n;
		VI a(n);
		VI c(3);
		_rep(i, 0, n){
			cin >> a[i];
			c[a[i] % 3] ++;
		}
		int ans = 0;
		int avg = n / 3;
		_rep(i, 0, 3){
			_rep(j, 0, 3){
				if(c[j] > avg) {
					ans += c[j] - avg;
					c[(j + 1) % 3] += c[j] - avg;
					c[j] = avg;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
} 
// 小心左移运算符导致的int溢出
// dp记得处理非法状态
// resize并不会初始化数组
// 全局函数一定要记得inline
// 带空格字符串不能直接cin,要用getline

