#include<bits/stdc++.h>
#include<bitset>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define ll              long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

// #################################################### //

void solve() {
    int x;
    cin >> x;
    vector<int> s(3,0);
    
    for(int i=0;i<x;i++) {
        int b;
        cin >> b;
        if(b%3==0) {
            s[0]++;
        } else if(b%3==1) {
            s[1]++;
        } else {
            s[2]++;
        }
    }
    
    int counter=0;
    int e=x/3;
    // cout << "e = " << e << endl;
    int i=0;
    
    while(1) {
        // cout << "i = " << i << " ,s[i] = " << s[i] << endl;
        if(s[i]>e) {
            s[i]--;
            s[(i+1)%3]++;
            counter++;
        } if(s[i]<=e) {
            i=(i+1)%3;
        }
        // cout << "s[0] = " << s[0] << " , s[1] = " << s[1] << " , s[2] = " << s[2] << endl;
        if(s[0]==e && s[1]==e && s[2]==e) {
            break;
        }
    }
    
    cout << counter << endl;
    
}

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	int t;
	cin >> t;
	while(t--) {
	    solve();
	}
    
	return 0;
}

