#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define ll long long int
#define repN(i, n) for(ll i = 0; i < (ll)N; i ++)
#define rep(i, a, b) for(ll i = a; i <= (ll)b; i ++)
#define dep(i, a ,b) for(ll i = a; i >= (ll)b; i --)
#define pr(x) cout << x;
#define prl(x) cout << x << endl;
#define FIO ios::sync_with_stdio(false);//cin.tie(nullptr);


int main() {
  int t;
  cin >> t;
  while(t --) {
    int n, c0 = 0, c1 = 0, c2 = 0;
    cin >> n;
    int a[n];
    for(int &i : a) {
      cin >> i;
      if(i % 3 == 0)
        c0 ++;
      else if(i % 3 == 1)
        c1 ++;
      else
        c2 ++;
    }
    int ans = 0;
    while(c0 != c1 || c1 != c2) {
      if(c0 > n/3)
        ans += c0 - n/3, c1 += c0 - n/3, c0 = n/3;
      if(c1 > n/3)
        ans += c1 - n/3, c2 += c1 - n/3, c1 = n/3;
      if(c2 > n/3)
        ans += c2 - n/3, c0 += c2 - n/3, c2 = n/3;
    }
    cout << ans << endl;
  }
}
