# 702 B思路:先把c0 c1 c2记录下来然后依次循环移动,记录下移动次数就好#include<stdio.h>#include <iostream>#include <cstring>#include <algorithm>using namespace std;int ai[30010];int main(){ int t; scanf("%d",&t); while(t--) { int n; int c0=0,c1=0,c2=0,c3=0; scanf("%d", &n); for(int i=1;i<=n;i++) { scanf("%d",&ai[i]); if(ai[i]%3==0)c0++; if(ai[i]%3==1)c1++; if(ai[i]%3==2)c2++; if(ai[i]==0)c3++; } int res=0; if(c0==c1&&c1==c2)printf("0\n"); else { while(!(c0==c1&&c1==c2)) { if(c0>c1) { res++; c0--; c1++; } if(c1>c2) { res++; c1--; c2++; } if(c2>c0) { res++; c2--; c0++; } } printf("%d\n",res);} } return 0;}