package competitive;
import java.util.*;
public class Pignhole_Principal {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
long arr[] = new long[n];
for (int i = 0; i < arr.length; i++) {
arr[i] = sc.nextLong();
}
System.out.println(sumofsubarray(arr, n));
}
}
public static long sumofsubarray(long[] arr, int n) {
long[] ans = new long[n];
long sum = 0;
ans[0] = 1;
for (int i = 0; i < n; i++) {
sum += arr[i];
if (sum < 0) {
int p = (int) ((sum + n) % n);
ans[p]++;
} else
ans[(int) (sum % n)]++;
}
long fs = 0;
for (int i = 0; i < n; i++) {
if (ans[i] >= 2) {
fs += (ans[i] * (ans[i] - 1)) / 2;
}
}
return fs;
}
}