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

#define fi first
#define se second
#define ll long long
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define pll pair<long, long>
#define int long long
#define sp << " " <<
#define sp << " " <<
#define spe << " "
#define en << endl

#define mem(a, b) memset(a, b, sizeof(a))
#define vi vector<int>
#define all(a) a.begin(), a.end()
#define getarr(a) \
  for (int &x : a) cin >> x;
#define read(x) \
  int(x);       \
  cin >> (x);

#define IOS                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL);
#define endl "\n";

const int mod = 1000000007;

int32_t main() {
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  IOS;
  read(test);
  while (test--) {
    int n;
    cin >> n;
    vi a(n);

    int c1 = 0, c2 = 0, c0 = 0;

    unordered_map<int, int> freq;
    for (int &x : a) {
      cin >> x;
      if (x % 3 == 1) {
        c1++;
      } else if (x % 3 == 2) {
        c2++;
      } else {
        c0++;
      }
    }

    int total = (c1 + c2 + c0) / 3;
    int ans = 0;

    while (c0 > total) {
      if (c1 < total) {
        ans++;
        c0--;
        c1++;
      }

      if (c2 < total) {
        ans += 2;
        c0--;
        c2++;
      }
    }

    while (c1 > total) {
      if (c0 < total) {
        ans += 2;
        c1--;
        c0++;
      }

      if (c2 < total) {
        ans += 1;
        c1--;
        c2++;
      }
    }

    while (c2 > total) {
      if (c0 < total) {
        ans += 1;
        c2--;
        c0++;
      }

      if (c1 < total) {
        ans += 2;
        c2--;
        c1++;
      }
    }

    cout << ans en;
  }
  return 0;
}