import java.util.*;
import java.io.*;
public class Main {
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
}
public static void main (String args[]){
FastReader s=new FastReader();
int t = s.nextInt();
while(t-->0){
int n=s.nextInt();
int []arr=new int[n];
for(int i=0;i<arr.length;i++){
arr[i]=s.nextInt();
}
int ans=fnosas(arr);
System.out.println(ans);
}
}
public static int fnosas(int []arr){
HashMap<Integer,Integer> maps=new HashMap<Integer,Integer>();
int[]prefix=new int[arr.length];
prefix[0]=arr[0];
for(int i=1;i<arr.length;i++){
prefix[i]=prefix[i-1]+arr[i];
}
for(int i=0;i<prefix.length;i++){
maps.put(prefix[i], maps.getOrDefault(prefix[i], 0) + 1);
}
int count=0;
for(int key:maps.keySet()){
int val=maps.get(key);
if(val>1){
count+=val*(val-1)/2;
}
}
return count;
}
}