import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class CustomTrack {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int T = Integer.parseInt(br.readLine());
        
        while (T-- > 0) {
            int N = Integer.parseInt(br.readLine());
            String line[] = br.readLine().split(" ");
            
            int rem = 0;
            for (int i = 0; i < N; i++) {
                rem = (rem + Integer.parseInt(line[i])) % N;
            }
            
            System.out.println(rem * (N - rem));
        }
    }
}