Pay attention to the non-standard memory limit in this problem.

In order to cut off efficient solutions from inefficient ones in this problem, the time limit is rather strict. Prefer to use compiled statically typed languages (e.g. C++). If you use Python, then submit solutions on PyPy. Try to write an efficient solution.

The array $a=[a_1, a_2, \ldots, a_n]$ ($1 \le a_i \le n$) is given. Its element $a_i$ is called special if there exists a pair of indices $l$ and $r$ ($1 \le l < r \le n$) such that $a_i = a_l + a_{l+1} + \ldots + a_r$. In other words, an element is called special if it can be represented as the sum of two or more consecutive elements of an array (no matter if they are special or not).

Print the number of special elements of the given array $a$.

For example, if $n=9$ and $a=[3,1,4,1,5,9,2,6,5]$, then the answer is $5$:  $a_3=4$ is a special element, since $a_3=4=a_1+a_2=3+1$;  $a_5=5$ is a special element, since $a_5=5=a_2+a_3=1+4$;  $a_6=9$ is a special element, since $a_6=9=a_1+a_2+a_3+a_4=3+1+4+1$;  $a_8=6$ is a special element, since $a_8=6=a_2+a_3+a_4=1+4+1$;  $a_9=5$ is a special element, since $a_9=5=a_2+a_3=1+4$. 

Please note that some of the elements of the array $a$ may be equal — if several elements are equal and special, then all of them should be counted in the answer.


-----Input-----

The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases in the input. Then $t$ test cases follow.

Each test case is given in two lines. The first line contains an integer $n$ ($1 \le n \le 8000$) — the length of the array $a$. The second line contains integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$).

It is guaranteed that the sum of the values of $n$ for all test cases in the input does not exceed $8000$.


-----Output-----

Print $t$ numbers — the number of special elements for each of the given arrays.


-----Example-----
Input
5
9
3 1 4 1 5 9 2 6 5
3
1 1 2
5
1 1 1 1 1
8
8 7 6 5 4 3 2 1
1
1

Output
5
1
0
4
0

Difficulty: EASY

Solutions:
from sys import stdin
from collections import Counter
input = stdin.readline

def main():
	test = int(input())
	for t in range(test):
		n = int(input())
		l = [int(i) for i in input().split(' ')]
		d = dict(Counter(l))
		count = 0
		for i in range(0, n):
			s = l[i]
			for j in range(i + 1, n):
				s += l[j]
				if s in d:
					count += d.get(s)
					del d[s]
		print(count)
main()


import sys
from collections import Counter
inp = sys.stdin.readline
read = lambda : list(map(int, inp().strip().split()))

def a():
	ans = ''
	for _ in range(int(inp())):
		n = int(inp())
		tem = ''
		x = 0
		c = 0
		while n:
			if n % 10:
				c += 1
				tem += str(n % 10 * 10 ** x) + ' '
			x += 1
			n //= 10
		ans += str(c) + '\n' + tem + '\n'
	print(ans)

def b():
	ans = ''
	for _ in range(int(inp())):
		(n, k) = read()
		if n == k:
			ans += 'YES\n'
			ans += '1 ' * k + '\n'
		elif k > n:
			ans += 'NO\n'
		elif n % 2 == 0:
			if k <= n // 2:
				ans += 'YES\n'
				for i in range(k - 1):
					ans += '2 '
					n -= 2
				ans += str(n) + '\n'
			elif k % 2 == 0:
				ans += 'YES\n'
				for i in range(k - 1):
					ans += '1 '
					n -= 1
				ans += str(n) + '\n'
			else:
				ans += 'NO\n'
		elif k % 2 == 0:
			ans += 'NO\n'
		else:
			ans += 'YES\n'
			for i in range(k - 1):
				ans += '1 '
				n -= 1
			ans += str(n) + '\n'
	print(ans)

def c():
	ans = ''
	for _ in range(int(inp())):
		(k, n) = read()
		n += (n + n // k) // k
		if n % k == 0:
			n += 1
		ans += str(n) + '\n'
	print(ans)

def d():
	ans = ''
	for _ in range(int(inp())):
		n = int(inp())
		arr = read()
		tem = 0
		dic = Counter(arr)
		for i in range(n):
			s = arr[i]
			for j in range(i + 1, n):
				s += arr[j]
				if s in dic:
					tem += dic[s]
					del dic[s]
		ans += str(tem) + '\n'
	print(ans)
d()


import sys

def input():
	return sys.stdin.buffer.readline()[:-1]
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	s = set()
	M = max(a)
	for i in range(n - 1):
		tmp = a[i]
		for j in range(i + 1, n):
			tmp += a[j]
			if tmp > M:
				break
			s.add(tmp)
	print(sum((x in s for x in a)))
	del s


n = int(input())
d = {}
x = 0
z = 0
for i in range(n):
	d = {}
	x = 0
	z = 0
	v = int(input())
	f = [int(i) for i in input().split()]
	for i in f:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	for i in range(v):
		z = f[i]
		for e in range(i + 1, v):
			z += f[e]
			if z in d:
				x += d[z]
				d[z] = 0
	print(x)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	s = [0] * (n + 1)
	for a_i in a:
		s[a_i] += 1
	c = 0
	for i in range(n - 1):
		s_i = a[i]
		for j in range(i + 1, n):
			s_i += a[j]
			if s_i > n:
				break
			if s[s_i] > 0:
				c += s[s_i]
				s[s_i] = 0
	print(c)


def solve(*a):
	N = len(a)
	d = [0] * (N + 1)
	for i in range(N - 1):
		cur = a[i]
		for j in range(i + 1, N):
			cur += a[j]
			if cur > N:
				break
			d[cur] = 1
	count = 0
	for x in a:
		count += d[x]
	print(count)

def read_a(s):
	return map(int, s.split())
for s in (*open(0),)[2::2]:
	solve(*read_a(s))


from itertools import accumulate
for _ in range(int(input())):
	n = int(input())
	data = list(map(int, input().split()))
	c = list(accumulate(data))
	s = set()
	for i in range(len(data) - 1):
		for j in range(i + 1, len(data)):
			if i == 0 and c[j] <= n:
				s.add(c[j])
			elif i != 0 and c[j] - c[i - 1] <= n:
				s.add(c[j] - c[i - 1])
	count = 0
	for i in data:
		if i in s:
			count += 1
	print(count)


for k in range(int(input())):
	x = int(input())
	y = [int(i) for i in input().split()]
	z = {}
	b = 0
	maxx = 0
	for j in y:
		if j > maxx:
			maxx = j
		if j not in z:
			z[j] = 1
		else:
			z[j] += 1
	for i in range(x):
		a = y[i]
		for j in range(i + 1, x):
			a += y[j]
			if a in z:
				b += z[a]
				z.pop(a)
			if a > maxx:
				break
	print(b)


cases = int(input())
for t in range(cases):
	n = int(input())
	b = [0] + list(map(int, input().split()))
	d = {}
	for i in range(n):
		if b[i + 1] in d:
			d[b[i + 1]] += 1
		else:
			d[b[i + 1]] = 1
		b[i + 1] += b[i]
	s = 0
	d1 = set()
	for i in range(n - 1):
		for j in range(i + 2, n + 1):
			v = b[j] - b[i]
			if v in d:
				d1.add(v)
	for i in d1:
		s += d[i]
	print(s)


for ii in range(int(input())):
	n = int(input())
	c = [int(i) for i in input().split()]
	dic = {}
	for i in c:
		if i in dic:
			dic[i] += 1
		else:
			dic[i] = 1
	ans = 0
	for i in range(1, n - 1):
		l = 0
		r = l + i
		sume = sum(c[l:r + 1])
		if sume <= n:
			if sume in dic:
				ans += dic[sume]
				dic[sume] = 0
		while r < n - 1:
			sume -= c[l]
			sume += c[r + 1]
			r += 1
			l += 1
			if sume <= n:
				if sume in dic:
					ans += dic[sume]
					dic[sume] = 0
	print(ans)


def solve():
	N = int(input())
	arr = [int(el) for el in input().split()]
	flg = [False for _ in range(8001)]
	for l in range(N):
		temp = arr[l]
		for r in range(l + 1, N):
			temp += arr[r]
			if temp < 8001:
				flg[temp] = True
	cnt = 0
	for item in arr:
		if flg[item]:
			cnt += 1
	return cnt
for t in range(1, int(input()) + 1):
	print(solve())


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	found = [False for i in range(n + 1)]
	for i in range(n - 1):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s > n:
				break
			found[s] = True
	c = 0
	for i in a:
		if found[i]:
			c += 1
	print(c)


import sys
t = int(input())
for _ in range(t):
	n = int(input())
	arr = input().split(' ')
	arr = list(map(int, arr))
	number = [0] * (n + 1)
	add = [0] * (n + 1)
	result = 0
	for a in arr:
		number[a] += 1
	for (i, a) in enumerate(arr):
		for j in range(i + 1):
			add[j] += a
			if j < i and add[j] <= n:
				result += number[add[j]]
				number[add[j]] = 0
	print(result)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	res = 0
	count = [0] * (n + 1)
	flag = False
	for l in range(len(arr)):
		s = arr[l]
		if flag:
			break
		for r in range(l + 1, len(arr)):
			s += arr[r]
			if s > n:
				break
			count[s] = 1
	for num in arr:
		if count[num] == 1:
			res += 1
	print(res)


from collections import Counter
from itertools import accumulate

def solve(n, a):
	if n < 3:
		return 0
	nums = Counter(a)
	specials = set()
	prefixes = list(accumulate(a))
	for size in range(1, n - 1):
		pos = 0
		while size + pos < n:
			subarray_sum = prefixes[pos + size] - (0 if pos == 0 else prefixes[pos - 1])
			if subarray_sum in nums:
				specials.add(subarray_sum)
			pos += 1
	ans = 0
	for elem in specials:
		ans += nums[elem]
	return ans
T = int(input())
for case in range(T):
	print(solve(int(input()), [int(x) for x in input().split()]))


from itertools import accumulate as acc
from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	t = [0] + [i for i in acc(l)]
	cc = Counter(l)
	r = 0
	for i in range(n):
		for j in range(i + 2, n + 1):
			s = t[j] - t[i]
			if s > n:
				break
			r += cc[s]
			del cc[s]
	print(r)


t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	lis = [0] * n
	pref = [arr[0]]
	for j in range(1, n):
		pref.append(pref[-1] + arr[j])
	for j in range(n):
		for k in range(j + 1, n):
			if j == 0:
				if pref[k] <= n:
					lis[pref[k] - 1] = 1
			elif pref[k] - pref[j - 1] <= n:
				lis[pref[k] - pref[j - 1] - 1] = 1
	ans = 0
	for j in range(n):
		if lis[arr[j] - 1] == 1:
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	lst = [int(i) for i in input().split()]
	pref = [0] * (len(lst) + 1)
	pref[0] = lst[0]
	for i in range(len(lst)):
		pref[i + 1] = pref[i] + lst[i]
	st = set()
	for i in range(len(pref)):
		for j in range(i + 2, len(pref)):
			if pref[j] - pref[i] <= n:
				st.add(pref[j] - pref[i])
	ans = 0
	for item in lst:
		if item in st:
			ans += 1
	print(ans)


def one_case():
	n = int(input())
	a = list(map(int, input().split()))
	ll = len(a)
	b = [0]
	for i in range(ll):
		b.append(a[i] + b[i])
	d = {}
	for i in range(ll - 1):
		for j in range(i + 2, ll + 1):
			t = b[j] - b[i]
			if t > n:
				continue
			d[t] = 1
	total = 0
	for i in a:
		total += d.get(i, 0)
	print(total)
t = int(input())
for i in range(t):
	one_case()


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	(cnt, ans) = ({}, 0)
	for i in range(n):
		if cnt.get(arr[i]):
			cnt[arr[i]] += 1
		else:
			cnt[arr[i]] = 1
	for l in range(n - 1):
		s = arr[l]
		for r in range(l + 1, n):
			s += arr[r]
			if cnt.get(s):
				ans += cnt[s]
				cnt[s] = 0
	print(ans)
for _ in range(int(input())):
	main()


def status(arr, req, n):
	l = 0
	r = 1
	flag = 0
	summ = arr[l] + arr[r]
	while flag != 1 and r < n and (l < n):
		if summ > req:
			summ -= arr[l]
			l += 1
		elif summ == req and r - l != 0:
			flag = 1
		elif r < n - 1:
			r += 1
			summ += arr[r]
		else:
			break
	return flag
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	cnt = 0
	if n == 1:
		print(0)
	else:
		for i in range(n):
			req = arr[i]
			if status(arr, req, n):
				cnt += 1
		print(cnt)


for i in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	pre = [0]
	for i in range(n):
		pre.append(pre[-1] + t[i])
	u = {}
	for i in t:
		if i in u:
			u[i] += 1
		else:
			u[i] = 1
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			temp = pre[j + 1] - pre[i]
			if temp in u and u[temp] != 0:
				ans += u[temp]
				u[temp] = 0
	print(ans)


import os
import sys
from io import BytesIO, IOBase

def main():
	for _ in range(int(input())):
		n = int(input())
		a = [int(x) for x in input().split()]
		(msk, vis, val) = ((2 << 12) - 1, 1 << 13, 1 << 14)
		ans = 0
		for x in a:
			x &= msk
			if a[x - 1] & vis:
				if a[x - 1] & val:
					ans += 1
				continue
			a[x - 1] |= vis
			(l, r) = (0, 0)
			cnt = 0
			while r < n:
				cnt += a[r] & msk
				r += 1
				while l < r and cnt > x:
					cnt -= a[l] & msk
					l += 1
				if cnt == x and r - l >= 2:
					ans += 1
					a[x - 1] |= val
					break
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys, math, cmath, time, io, os
from collections import defaultdict
start_time = time.time()
tt = 0

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())

def solve():
	n = inp()
	a = inlt()
	c = 0
	q = set()
	for i in range(len(a) - 1):
		w = a[i]
		for j in range(i + 1, len(a)):
			w += a[j]
			if w > n:
				break
			q.add(w)
	for i in range(len(a)):
		if a[i] in q:
			c = c + 1
	print(c)

def main():
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	t = inp()
	for tt in range(t):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
	sys.stdout.close()

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ma = max(a)
	mi = min(a)
	sums = set()
	for i in range(n):
		s = a[i]
		for j in a[i + 1:]:
			s += j
			if mi <= s <= ma:
				sums.add(s)
	c = 0
	for i in a:
		if i in sums:
			c += 1
	print(c)


from itertools import accumulate
import sys

def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def main():
	for _ in range(II()):
		n = II()
		aa = LI()
		cs = [0] + [s for s in accumulate(aa)]
		can = [False] * (n + 1)
		for l in range(n):
			for r in range(l + 2, n + 1):
				s = cs[r] - cs[l]
				if s > n:
					break
				can[cs[r] - cs[l]] = True
		ans = sum((can[a] for a in aa))
		print(ans)
main()


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = Counter(l)
	k = 0
	for x in range(n - 1):
		p = l[x]
		for y in range(x + 1, n):
			p += l[y]
			if p in c:
				k += c[p]
				del c[p]
	print(k)


from collections import Counter

class A:

	def solve(self):
		t = int(input())
		for i in range(t):
			n = list(map(int, input()))
			round_numbers = list(map(lambda x: x[0] * 10 ** x[1], filter(lambda x: x[0] > 0, zip(n, reversed(list(range(len(n))))))))
			print(len(round_numbers))
			print(' '.join(map(str, round_numbers)))

class B:

	def solve(self):
		t = int(input())
		for p in range(t):
			in_list = list(map(int, input().split(' ')))
			(n, k) = (in_list[0], in_list[1])
			if k % 2 == 1:
				if n % 2 == 0:
					first_term = n - (k - 1) * 2
					if first_term <= 0:
						print('NO')
						continue
					print('YES')
					print(' '.join([str(first_term)] + ['2' for x in range(k - 1)]))
				else:
					first_term = n - (k - 1)
					if first_term <= 0:
						print('NO')
						continue
					print('YES')
					print(' '.join([str(first_term)] + ['1' for x in range(k - 1)]))
			elif n % 2 == 0:
				first_term = n - (k - 1)
				if first_term <= 0:
					print('NO')
					continue
				if first_term % 2 == 1:
					print('YES')
					print(' '.join([str(first_term)] + ['1' for x in range(k - 1)]))
					continue
				first_term = n - (k - 1) * 2
				if first_term <= 0:
					print('NO')
					continue
				if first_term % 2 == 0:
					print('YES')
					print(' '.join([str(first_term)] + ['2' for x in range(k - 1)]))
				else:
					print('NO')
			else:
				print('NO')

class C:

	def solve(self):
		t = int(input())
		for p in range(t):
			in_list = list(map(int, input().split(' ')))
			(n, k) = (in_list[0], in_list[1])
			m = k // (n - 1)
			if k % (n - 1) == 0:
				print(m * n - 1)
				continue
			print(m * n + k % (n - 1))

class D:

	def solve(self):
		t = int(input())
		for p in range(t):
			n = int(input())
			candies = [int(x) for x in input().split(' ')]
			if len(candies) == 1:
				print('1 {} 0'.format(candies[0]))
				continue
			(b, a, n) = self.eat_candy(candies[1:], 1, 0, candies[0], 1, candies[0])
			print('{} {} {}'.format(n, a, b))

	def eat_candy(self, candies, turn, b_candy, a_candy, n_turns, previous_candy):
		if turn == 0:
			alice_sum = 0
			index = 0
			while index < len(candies) and alice_sum <= previous_candy:
				alice_sum += candies[index]
				index += 1
			if index == len(candies):
				return (b_candy, a_candy + alice_sum, n_turns + 1)
			else:
				return self.eat_candy(candies[index:], 1, b_candy, a_candy + alice_sum, n_turns + 1, alice_sum)
		else:
			bob_sum = 0
			index = len(candies) - 1
			while index >= 0 and bob_sum <= previous_candy:
				bob_sum += candies[index]
				index -= 1
			if index < 0:
				return (b_candy + bob_sum, a_candy, n_turns + 1)
			else:
				return self.eat_candy(candies[:index + 1], 0, b_candy + bob_sum, a_candy, n_turns + 1, bob_sum)

class E:

	def solve(self):
		t = int(input())
		for p in range(t):
			n = int(input())
			nums = [int(x) for x in input().split(' ')]
			counter = [0 for x in range(n + 1)]
			for i in nums:
				counter[i] += 1
			num_elem = 0
			for i in range(len(nums)):
				sum = 0
				for j in range(i, len(nums), 1):
					sum += nums[j]
					if i == j:
						continue
					if sum <= n and counter[sum] > 0:
						num_elem += counter[sum]
						counter[sum] = 0
			print(num_elem)
E().solve()


import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict, deque
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split(' ')))
	if n == 1:
		print(0)
	else:
		d = [0] * (n + 1)
		s = l[0]
		for i in range(1, n):
			s += l[i]
			f = s
			if s <= n:
				d[s] = 1
			for j in range(i - 1):
				f -= l[j]
				if f <= n:
					d[f] = 1
		ans = 0
		for i in range(n):
			ans += d[l[i]]
		print(ans)


from queue import deque
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	seen = set()
	for l in range(n - 1):
		tmp = a[l]
		for r in range(l + 1, n):
			if tmp + a[r] > n:
				break
			tmp += a[r]
			seen.add(tmp)
	ans = 0
	for i in a:
		if i in seen:
			ans += 1
	print(ans)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	li = [int(i) for i in input().split()]
	cnt = 0
	cnts = Counter(li)
	for i in range(n):
		sum = 0
		for j in range(i, n):
			sum += li[j]
			if i == j:
				continue
			if sum in cnts:
				cnt += cnts[sum]
				cnts[sum] = 0
	print(cnt)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ct = 0
	if n == 1:
		print(0)
	else:
		for i in range(n):
			l = 0
			r = 1
			s = a[l] + a[r]
			special = False
			while l < n - 1:
				if s == a[i]:
					special = True
					break
				if s > a[i]:
					s -= a[l]
					l += 1
					if l == r and r < n - 1:
						r += 1
						s += a[r]
				elif r < n - 1:
					r += 1
					s += a[r]
				else:
					break
			ct += special
		print(ct)


import collections
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ok = [0] * n
	poss = [[] for i in range(n + 1)]
	for i in range(n):
		poss[arr[i]].append([arr[i], i])
	lens = [len(poss[i]) for i in range(n + 1)]
	for l in range(n - 1):
		acum = arr[l]
		for r in range(l + 1, n):
			acum += arr[r]
			if acum > n:
				break
			if lens[acum] != 0:
				for i in range(lens[acum] - 1, -1, -1):
					if poss[acum][i][1] < l or poss[acum][i][1] > r:
						ok[poss[acum][i][1]] = 1
						del poss[acum][i]
						lens[acum] -= 1
	ans = 0
	for i in range(n):
		if ok[i] == 1:
			ans += 1
	print(ans)


from sys import stdin, stdout
import collections
t = int(input())

def solve(n, nums):
	cnts = collections.Counter(nums)
	cnt = 0
	for i in range(n):
		cur = nums[i]
		for j in range(i + 1, n):
			cur += nums[j]
			if cur in cnts:
				cnt += cnts[cur]
				cnts[cur] = 0
	print(cnt)
for i in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	solve(n, nums)


T = int(input())
for _ in range(T):
	n = int(input())
	values = list(map(int, input().split()))
	check = [0] * 8002
	for i in values:
		check[i] += 1
	prefix = [0] * (n + 1)
	prefix[0] = 0
	for i in range(n):
		prefix[i + 1] = prefix[i] + values[i]
	del values
	processed = [0] * 8002
	ans = 0
	for i in range(1, n + 1):
		for j in range(i + 1, n + 1):
			val = prefix[j] - prefix[i - 1]
			if val < 8001 and check[val] > 0 and (processed[val] == 0):
				processed[val] = 1
				ans += check[val]
	print(ans)


t = int(input())
k = 0
for _ in range(t):
	n = int(input())
	lis = list(map(int, input().split(' ')))
	pre = [0] * len(lis)
	pre[0] = lis[0]
	dic = {}
	flag = {}
	for i in lis:
		if i not in dic:
			dic[i] = 1
			flag[i] = 1
		else:
			dic[i] += 1
	ans = 0
	for i in range(1, len(lis)):
		pre[i] = pre[i - 1] + lis[i]
		if pre[i] in dic and flag[pre[i]]:
			flag[pre[i]] = 0
			ans += dic[pre[i]]
	for i in range(len(lis) - 2):
		for j in range(i + 2, len(lis)):
			if pre[j] - pre[i] in dic and flag[pre[j] - pre[i]]:
				flag[pre[j] - pre[i]] = 0
				ans += dic[pre[j] - pre[i]]
	print(ans)


import sys, bisect, string, math, time, functools, random
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby

def Golf():
	(*a,) = map(int, open(0))

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char] = (i + 1) * (w + 2) + s.index(char) + 1
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def bit_combination(k, n=2):
	rt = []
	for tb in range(n ** k):
		s = [tb // n ** bt % n for bt in range(k)]
		rt += [s]
	return rt

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(1, 0), (-1, 0), (0, 1), (0, -1)]
EightNb = [(1, 0), (-1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('EWNS', FourNb))
l_alp = string.ascii_lowercase
input = lambda : sys.stdin.readline().rstrip()

class Tree:

	def __init__(self, inp_size=None, init=True):
		self.LCA_init_stat = False
		self.ETtable = []
		if init:
			self.stdin(inp_size)
		return

	def stdin(self, inp_size=None, index=1):
		if inp_size == None:
			self.size = int(input())
		else:
			self.size = inp_size
		(self.edges, _) = GI(self.size, self.size - 1, index=index)
		return

	def listin(self, ls, index=0):
		self.size = len(ls) + 1
		(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def __str__(self):
		return str(self.edges)

	def dfs(self, x, func=lambda prv, nx, dist: prv + dist, root_v=0):
		q = deque()
		q.append(x)
		v = [-1] * self.size
		v[x] = root_v
		while q:
			c = q.pop()
			for (nb, d) in self.edges[c]:
				if v[nb] == -1:
					q.append(nb)
					v[nb] = func(v[c], nb, d)
		return v

	def EulerTour(self, x):
		q = deque()
		q.append(x)
		self.depth = [None] * self.size
		self.depth[x] = 0
		self.ETtable = []
		self.ETdepth = []
		self.ETin = [-1] * self.size
		self.ETout = [-1] * self.size
		cnt = 0
		while q:
			c = q.pop()
			if c < 0:
				ce = ~c
			else:
				ce = c
				for (nb, d) in self.edges[ce]:
					if self.depth[nb] == None:
						q.append(~ce)
						q.append(nb)
						self.depth[nb] = self.depth[ce] + 1
			self.ETtable.append(ce)
			self.ETdepth.append(self.depth[ce])
			if self.ETin[ce] == -1:
				self.ETin[ce] = cnt
			else:
				self.ETout[ce] = cnt
			cnt += 1
		return

	def LCA_init(self, root):
		self.EulerTour(root)
		self.st = SparseTable(self.ETdepth, init_func=min, init_idl=inf)
		self.LCA_init_stat = True
		return

	def LCA(self, root, x, y):
		if self.LCA_init_stat == False:
			self.LCA_init(root)
		(xin, xout) = (self.ETin[x], self.ETout[x])
		(yin, yout) = (self.ETin[y], self.ETout[y])
		a = min(xin, yin)
		b = max(xout, yout, xin, yin)
		id_of_min_dep_in_et = self.st.query_id(a, b + 1)
		return self.ETtable[id_of_min_dep_in_et]

class SparseTable:

	def __init__(self, ls, init_func=min, init_idl=float('inf')):
		self.func = init_func
		self.idl = init_idl
		self.size = len(ls)
		self.N0 = self.size.bit_length()
		self.table = [ls[:]]
		self.index = [list(range(self.size))]
		self.lg = [0] * (self.size + 1)
		for i in range(2, self.size + 1):
			self.lg[i] = self.lg[i >> 1] + 1
		for i in range(self.N0):
			tmp = [self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) for j in range(self.size)]
			tmp_id = [self.index[i][j] if self.table[i][j] == self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) else self.index[i][min(j + (1 << i), self.size - 1)] for j in range(self.size)]
			self.table += [tmp]
			self.index += [tmp_id]

	def query(self, l, r):
		r = min(self.size, r)
		N = self.lg[r - l]
		return self.func(self.table[N][l], self.table[N][r - (1 << N)])

	def query_id(self, l, r):
		N = self.lg[r - l]
		(a, b) = (self.index[N][l], self.index[N][r - (1 << N)])
		if self.table[0][a] == self.func(self.table[N][l], self.table[N][r - (1 << N)]):
			b = a
		return b

	def __str__(self):
		return str(self.table[0])

	def print(self):
		for i in self.table:
			print(*i)
show_flg = False
show_flg = True
ans = 0
T = I()
for _ in range(T):
	n = I()
	a = LI()
	A = max(a)
	b = [0]
	m = defaultdict(int)
	ans = 0
	for i in a:
		m[i] += 1
	for i in a:
		b += [b[-1] + i]
	for i in range(n):
		for j in range(i + 1, n):
			if b[j + 1] - b[i] in m:
				m[b[j + 1] - b[i]] = 0
			if b[j + 1] - b[i] >= A:
				break
	for (i, j) in m.items():
		ans += j
	print(n - ans)


def r(t=int):
	return list(map(t, input().split()))

def ri(t=int):
	return t(input())

def cd(it):
	ret_val = dict()
	for v in it:
		ret_val[v] = ret_val.get(v, 0) + 1
	return ret_val
for _ in range(ri()):
	n = ri()
	a = r()
	c = cd(a)
	ans = 0
	for (ck, cv) in c.items():
		(k0, k1) = (0, 0)
		for (n, i) in enumerate(a):
			if i >= ck:
				k0 = 0
				k1 = n + 1
				continue
			k0 += i
			if k0 < ck:
				continue
			if k0 > ck:
				while k0 > ck:
					k0 -= a[k1]
					k1 += 1
			if k0 == ck and k1 != n:
				ans += cv
				break
	print(ans)


import sys
input = sys.stdin.buffer.readline
T = int(input())
for testcase in range(T):
	n = int(input())
	a = tuple(map(int, input().split()))
	b = [0]
	for e in a:
		b.append(b[-1] + e)
	c = set()
	for i in range(n + 1):
		for j in range(i + 2, n + 1):
			if b[j] - b[i] <= n:
				c.add(b[j] - b[i])
	res = 0
	for e in a:
		if e in c:
			res += 1
	print(res)


from sys import stdin, stdout
from math import *
from collections import Counter
from collections import defaultdict

def solve(l):
	n = len(l)
	D = Counter(l)
	out = 0
	pr = [0]
	dd = {0: 0}
	for i in range(len(l)):
		pr.append(pr[-1] + l[i])
		dd[pr[-1]] = i + 1
	for k in D:
		summ = 0
		ans = -1
		for i in range(len(pr)):
			if pr[i] >= k:
				req = pr[i] - k
				if dd.get(req) != None:
					ans = dd.get(req)
				if ans != -1 and i - ans > 1:
					break
				ans = -1
		if ans != -1:
			out += D[k]
	return out
for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	print(solve(ar))


import math
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = [0] * n
	s = [0, a[0]]
	for i in range(1, n):
		s.append(s[-1] + a[i])
	for i in range(n - 1):
		for j in range(i + 1, n):
			r = s[j + 1] - s[i]
			if r <= n:
				d[r - 1] = 1
	answer = 0
	for i in range(n):
		answer += d[a[i] - 1]
	print(answer)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def su(arr, n, sum):
	curr_sum = arr[0]
	start = 0
	i = 1
	while i <= n:
		while curr_sum > sum and start < i - 1:
			curr_sum = curr_sum - arr[start]
			start += 1
		if curr_sum == sum and start != i - 1:
			return 1
		if i < n:
			curr_sum = curr_sum + arr[i]
		i += 1
	return 0
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	for i in range(n):
		if i != 0 and su(l[0:i], i, l[i]) == 1:
			c += 1
		elif i != n - 1 and su(l[i + 1:n], n - (i + 1), l[i]) == 1:
			c += 1
	print(c)


import sys
import os
from math import sqrt, log, log2, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
from sys import exit, stdin, stdout
from collections import Counter, defaultdict, deque
from itertools import permutations
import heapq
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = 1000000007
iinp = lambda : int(sys.stdin.readline())
inp = lambda : sys.stdin.readline().strip()
strl = lambda : list(inp().strip().split(' '))
intl = lambda : list(map(int, inp().split(' ')))
mint = lambda : map(int, inp().split())
flol = lambda : list(map(float, inp().split(' ')))
flush = lambda : stdout.flush()

def permute(nums):

	def fun(arr, nums, cur, v):
		if len(cur) == len(nums):
			arr.append(cur.copy())
		i = 0
		while i < len(nums):
			if v[i]:
				i += 1
				continue
			else:
				cur.append(nums[i])
				v[i] = 1
				fun(arr, nums, cur, v)
				cur.pop()
				v[i] = 0
				i += 1
		return arr
	res = []
	nums.sort()
	v = [0] * len(nums)
	return fun(res, nums, [], v)

def subsets(res, index, arr, cur):
	res.append(cur.copy())
	for i in range(index, len(arr)):
		cur.append(arr[i])
		subsets(res, i + 1, arr, cur)
		cur.pop()
	return res

def sieve(N):
	root = int(sqrt(N))
	primes = [1] * (N + 1)
	(primes[0], primes[1]) = (0, 0)
	for i in range(2, root + 1):
		if primes[i]:
			for j in range(i * i, N + 1, i):
				primes[j] = 0
	return primes

def bs(arr, l, r, x):
	if x < arr[0] or x > arr[len(arr) - 1]:
		return -1
	while l <= r:
		mid = l + (r - l) // 2
		if arr[mid] == x:
			return mid
		elif arr[mid] < x:
			l = mid + 1
		else:
			r = mid - 1
	return -1

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	p = int(sqrt(n))
	for i in range(5, p + 1, 6):
		if n % i == 0 or n % (i + 2) == 0:
			return False
	return True

def solve():
	n = iinp()
	arr = intl()
	d = set()
	for l in range(n - 1):
		s = arr[l]
		for r in range(l + 1, n):
			s += arr[r]
			if s <= n:
				d.add(s)
			if s > n:
				break
	ans = 0
	for i in range(n):
		if arr[i] in d:
			ans += 1
	print(ans)
for _ in range(iinp()):
	solve()


t = int(input())

def solve():
	n = int(input())
	arr = [int(i) for i in input().split(' ')]
	freq = [0 for i in range(n + 1)]
	for x in arr:
		freq[x] += 1
	cnt = 0
	for i in range(n):
		summ = 0
		for j in range(i, n):
			summ += arr[j]
			if i == j:
				continue
			if summ <= n:
				cnt += freq[summ]
				freq[summ] = 0
	print(cnt)
for i in range(t):
	solve()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	m = max(l)
	s = set()
	temp_sum = 0
	count = 0
	for i in range(n):
		temp_sum = l[i]
		if l[i] == m:
			continue
		for j in range(i + 1, n):
			temp_sum += l[j]
			if temp_sum > m:
				break
			s.add(temp_sum)
	for i in range(n):
		if l[i] in s:
			count += 1
	print(count)


c = int(input())
for _ in range(c):
	n = int(input())
	a = list(map(int, input().split()))
	m = max(a)
	l = {}
	for i in range(n):
		s = a[i]
		cnt = 1
		while i + cnt < n:
			s += a[i + cnt]
			if s not in l:
				l[s] = 1
			cnt += 1
			if s >= m:
				break
	ans = 0
	for i in range(n):
		if a[i] in l:
			ans += 1
	print(ans)


import sys
T = int(sys.stdin.readline())
for _ in range(T):
	N = int(sys.stdin.readline())
	list_num = list(map(int, sys.stdin.readline().split()))
	list_check = [[0, N + 1] for _ in range(N + 1)]
	save_sum = sum(list_num[:1])
	for r in range(2, N):
		s = 0
		e = r - 1
		save_sum += list_num[e]
		now_sum = save_sum
		if now_sum <= N and list_check[now_sum][1] > e + 1:
			list_check[now_sum][1] = e + 1
		if now_sum <= N and list_check[now_sum][0] < s + 1:
			list_check[now_sum][0] = s + 1
		for i in range(N - r):
			now_sum -= list_num[s]
			e += 1
			s += 1
			now_sum += list_num[e]
			if now_sum <= N and list_check[now_sum][1] > e + 1:
				list_check[now_sum][1] = e + 1
			if now_sum <= N and list_check[now_sum][0] < s + 1:
				list_check[now_sum][0] = s + 1
	result = 0
	for (i, num) in enumerate(list_num):
		if list_check[num][1] <= i + 1:
			result += 1
		elif list_check[num][0] >= i + 1:
			result += 1
	print(result)


t = int(input())
for x in range(t):
	n = int(input())
	l = [0] * (n + 1)
	a = list(map(int, input().split()))
	for x in a:
		l[x] += 1
	ans = 0
	for i in range(n):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s <= n:
				ans += l[s]
				l[s] = 0
			else:
				break
	print(ans)


from sys import *
input = stdin.readline
for u in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = [0] * (n + 1)
	for i in range(n - 1):
		s = l[i]
		for j in range(i + 1, n):
			s = s + l[j]
			if s > n:
				break
			d[s] += 1
	c = 0
	for i in range(n):
		if d[l[i]] > 0:
			c = c + 1
	print(c)


t = int(input())
while t > 0:
	n = int(input())
	arr = list(map(int, input().split()))
	yes = [False] * (n + 1)
	for i in range(n):
		su = arr[i]
		for j in range(i + 1, n):
			su += arr[j]
			if su <= n:
				yes[su] = True
	ans = 0
	for x in arr:
		if yes[x] == True:
			ans += 1
	print(ans)
	t -= 1


def resolve():
	from itertools import accumulate
	from collections import Counter
	t = int(input())
	for _ in range(t):
		ans = 0
		n = int(input())
		a = list(map(int, input().split()))
		c = Counter(a)
		b = [0] + list(accumulate(a))
		for i in range(n - 1):
			for j in range(i + 2, n + 1):
				k = b[j] - b[i]
				if k in c:
					ans += c.pop(k)
		print(ans)
resolve()


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	sums = [False] * (n + 1)
	for i in range(n):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s <= n:
				sums[s] = True
	count = 0
	for x in a:
		if sums[x]:
			count += 1
	print(count)


from collections import Counter
from collections import defaultdict
import math
import sys
input = sys.stdin.readline
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rls = lambda : list(map(str, input().split()))
from collections import deque
t = int(input())
for _ in range(0, t):
	n = int(input())
	a = rl()
	d = [0] * (n + 1)
	ans = 0
	for i in range(1, n + 1):
		d[i] = d[i - 1] + a[i - 1]
	for i in range(0, n):
		l = 0
		r = 1
		while r < n + 1 and l < n + 1:
			diff = d[r] - d[l]
			if diff > a[i]:
				l = l + 1
			elif diff < a[i]:
				r = r + 1
			elif r - l >= 2:
				ans = ans + 1
				break
			else:
				l = l + 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	ar = [int(x) for x in input().split()]
	d = {}
	for i in ar:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	ans = 0
	for i in range(n - 1):
		sm = ar[i]
		for j in range(i + 1, n):
			sm += ar[j]
			if sm in d and d[sm] > 0:
				ans += d[sm]
				d[sm] = 0
	print(ans)


from sys import stdin

def iinput():
	return int(stdin.readline())

def minput():
	return map(int, stdin.readline().split())

def linput():
	return list(map(int, stdin.readline().split()))
from collections import Counter
t = iinput()
while t:
	t -= 1
	n = iinput()
	a = linput()
	c = Counter(a)
	ans = 0
	for i in range(n - 1):
		temp = a[i]
		for j in range(i + 1, n):
			temp += a[j]
			if temp in c:
				ans += c[temp]
				c[temp] = 0
	print(ans)


for f in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	good = [0] * (n + 1)
	poss = []
	for i in range(n):
		poss2 = []
		for j in range(len(poss)):
			if poss[j] + a[i] <= n:
				poss2.append(poss[j] + a[i])
				good[poss[j] + a[i]] = 1
		poss2.append(a[i])
		poss = poss2
	spec = 0
	for i in range(n):
		if good[a[i]] == 1:
			spec += 1
	print(spec)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	prefSum = [0] * (n + 1)
	for i in range(n):
		prefSum[i + 1] = prefSum[i] + a[i]
	has = [0] * (n + 1)
	for i in range(n):
		for j in range(i + 2, n + 1, 1):
			if -prefSum[i] + prefSum[j] <= n:
				has[-prefSum[i] + prefSum[j]] = 1
			else:
				break
	cunt = 0
	for i in range(n):
		cunt += has[a[i]]
	print(cunt)


def task(n, a):
	table = {}
	total = 0
	mx = 0
	for i in range(0, n):
		if not a[i] in table:
			table[a[i]] = 0
		table[a[i]] += 1
		mx = max(mx, a[i])
	for l in range(0, n - 1):
		suma = a[l]
		for r in range(l + 1, n):
			suma += a[r]
			if suma in table:
				total += table[suma]
				del table[suma]
			elif suma > mx:
				break
	print(total)
t = int(input())
for i in range(0, t):
	n = int(input())
	a = list(map(int, input().split()))
	task(n, a)


import sys
import os
from io import BytesIO, IOBase

def cel(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def dd():
	return defaultdict(int)

def ddl():
	return defaultdict(list)

def ddd():
	return defaultdict(defaultdict(int))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
from bisect import bisect_left as bl
for _ in range(ii()):
	n = ii()
	a = li()
	values_count = [0 for i in range(n + 1)]
	for i in range(n):
		values_count[a[i]] += 1
	ans = 0
	for i in range(n - 1):
		sm = 0
		for j in range(i, n):
			sm += a[j]
			if i == j:
				continue
			if sm <= n:
				ans += values_count[sm]
				values_count[sm] = 0
	print(ans)


test = int(input())
for _ in range(test):
	n = int(input())
	a = [int(x) for x in input().split()]
	cnt = [0 for i in range(n + 1)]
	for i in a:
		cnt[i] += 1
	ans = 0
	for i in range(n):
		sm = a[i]
		for j in range(i + 1, n):
			sm += a[j]
			if sm <= n:
				ans += cnt[sm]
				cnt[sm] = 0
	print(ans)


from collections import defaultdict
for T in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	l = [0] * (n + 1)
	for i in range(n - 1):
		temp = arr[i]
		for i in range(i + 1, n):
			temp += arr[i]
			if temp <= n:
				l[temp] = 1
	ans = 0
	for i in range(n):
		ans += l[arr[i]]
	print(ans)


from sys import stdin, stdout
t = int(stdin.readline().rstrip())

def main():
	n = int(stdin.readline().rstrip())
	a = [0] + list(map(int, stdin.readline().strip().split()))
	cnt = [0 for i in range(n + 1)]
	p = [0]
	for i in range(1, n + 1):
		p.append(p[i - 1] + a[i])
		cnt[a[i]] += 1
	tot = 0
	for i in range(1, n + 1):
		for j in range(i - 1):
			x = p[i] - p[j]
			if x <= n:
				tot += cnt[x]
				cnt[x] = 0
	stdout.write('{}\n'.format(tot))
for i in range(t):
	main()


from collections import deque as dq
for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	freq = {}
	for i in a:
		if freq.get(i, 0) == 0:
			freq[i] = 1
		else:
			freq[i] += 1
	a1 = list(set(a))
	pref = [0, a[0]]
	for i in range(1, n):
		pref.append(pref[-1] + a[i])
	visited = {}
	ans = 0
	for i in range(2, n + 1):
		for j in range(1, i):
			x = pref[i] - pref[j - 1]
			if freq.get(x, 0) != 0 and visited.get(x, False) == False:
				ans += freq[x]
				visited[x] = True
	print(ans)


def process_test_case(i_t):
	n = int(input())
	a_vec = list(map(int, input().split()))
	a_cum_vec = a_vec.copy()
	for i in range(1, n):
		a_cum_vec[i] += a_cum_vec[i - 1]
	a_cum_vec = [0] + a_cum_vec
	sub_sum_vec = [False] * n
	for i in range(1, n):
		for j in range(i + 1, n + 1):
			ij_sum = a_cum_vec[j] - a_cum_vec[i - 1]
			if ij_sum <= n:
				sub_sum_vec[ij_sum - 1] = True
	ans = 0
	for i in range(n):
		ans += sub_sum_vec[a_vec[i] - 1]
	print(ans)
	return None
n_tests = int(input())
for i_test in range(1, n_tests + 1):
	process_test_case(i_test)


t = int(input())
for z in range(t):
	s = set()
	ma = -1
	ans = 0
	n = int(input())
	a = list(map(int, input().split()))
	for i in range(n):
		ma = max(a[i], ma)
	for i in range(n - 1):
		cur = a[i]
		for j in range(i + 1, n):
			cur += a[j]
			if cur <= ma:
				s.add(cur)
			else:
				break
	for i in range(n):
		if a[i] in s:
			ans += 1
	print(ans)


for testcase in range(int(input())):
	n = int(input())
	data = list(map(int, input().split()))
	visited = set()
	for i in range(n):
		summary = data[i]
		for j in range(i + 1, n):
			summary += data[j]
			if summary > n:
				break
			visited.add(summary)
	result = 0
	for x in data:
		if x in visited:
			result += 1
	print(result)


def sol():
	am = int(input())
	arr = list(map(int, input().split()))
	if am == 0:
		print(0)
		return 0
	was = [False] * (am * 2 + 1)
	for i in range(1, am - 1):
		s = sum(arr[:am - i])
		if s <= am:
			was[s] = True
		for g in range(1, i + 1):
			s -= arr[g - 1]
			s += arr[g + (am - i) - 1]
			if s <= am:
				was[s] = True
	c = 0
	for i in range(am):
		if was[arr[i]]:
			c += 1
	print(c)
for g in range(int(input())):
	sol()


def main():
	input()
	a = list(map(int, input().split()))
	len_a = len(a)
	if len_a == 1:
		print(0)
		return
	t = 0
	for an in a:
		i = 0
		j = 1
		res = a[i] + a[j]
		while True:
			if res == an:
				t += 1
				break
			if res < an:
				if j < len_a - 1:
					j += 1
					res += a[j]
				else:
					break
			if res > an:
				res -= a[i]
				i += 1
				if i > j - 1:
					if j < len_a - 1:
						j += 1
						res += a[j]
					else:
						break
	print(t)
for _ in range(int(input())):
	main()


n = int(input())
for i in range(n):
	num = int(input())
	nums = input().split()
	a = [int(j) for j in nums]
	prefix = [0]
	cnt = 0
	flag = {}
	for j in range(8005):
		flag[j] = 0
	for j in range(0, len(a)):
		flag[a[j]] += 1
		prefix.append(prefix[j] + a[j])
	for j in range(0, len(prefix) - 2):
		for k in range(j + 2, len(prefix)):
			if prefix[k] - prefix[j] > num:
				break
			cnt += flag[prefix[k] - prefix[j]]
			flag[prefix[k] - prefix[j]] = 0
	print(cnt)


def subarray_sum_k(a, k):
	count = 0
	if a:
		d = {0: 1}
		s = 0
		for i in a:
			s += i
			if s - k in d:
				count += d[s - k]
			d[s] = d.get(s, 0) + 1
	return count

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	c = {}
	for i in a:
		c[i] = c.get(i, 0) + 1
	count = 0
	for (i, ai) in enumerate(a[:-1]):
		s = ai
		for (j, aj) in enumerate(a[i + 1:]):
			s += aj
			if s in c:
				count += c[s]
				del c[s]
	print(count)

def main():
	t = int(input())
	for _ in range(t):
		solve()
main()


for _ in range(int(input())):
	n = int(input())
	l = [int(x) for x in input().split()]
	d = {}
	for i in l:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	ans = 0
	for i in range(n):
		s = 0
		for j in range(i, n):
			s += l[j]
			if j != i:
				if s in d:
					ans += d[s]
					d[s] = 0
	print(ans)


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(e) for e in input().split()]
	dp = [0]
	for i in range(n):
		dp.append(dp[-1] + arr[i])
	fq = Counter(arr)
	s = 0
	for i in range(1, n + 1):
		for j in range(i + 1, n + 1):
			d = dp[j] - dp[i - 1]
			if d in fq:
				s += fq[d]
				fq[d] = 0
	print(s)


t = int(input())
for z in range(t):
	n = int(input())
	data = input().split()
	array = []
	for y in range(n):
		array.append(int(data[y]))
	if len(array) == 1:
		print(0)
	else:
		count = 0
		for a in array:
			i = 0
			j = 1
			total = array[i] + array[j]
			while 1 == 1:
				if total == a:
					count += 1
					break
				elif (j - i == 1 or total < a) and j == n - 1:
					break
				elif j - i == 1 or total < a:
					total += array[j + 1]
					j += 1
				else:
					total -= array[i]
					i += 1
		print(count)


import sys
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
import collections as col

def solve():
	N = getInt()
	A = getInts()
	a_els = col.defaultdict(int)
	prefix_sums = [0]
	curr_sum = 0
	for a in A:
		curr_sum += a
		a_els[a] += 1
		prefix_sums.append(curr_sum)
	ans = 0
	for l in range(1, N + 1):
		for r in range(l + 1, N + 1):
			q = prefix_sums[r] - prefix_sums[l - 1]
			if q in a_els:
				ans += a_els[q]
				del a_els[q]
	return ans
T = getInt()
for t in range(T):
	print(solve())


t = int(input())
for kek in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	if len(a) < 2:
		print(0)
		continue
	ans = 0
	osob = set()
	for i in a:
		if i in osob:
			ans += 1
			continue
		l = 0
		r = 1
		s = a[0] + a[1]
		while True:
			if s == i and r - l >= 1:
				ans += 1
				osob.add(i)
				break
			elif s < i:
				r += 1
				if r == len(a):
					break
				s += a[r]
			else:
				s -= a[l]
				l += 1
				if l == len(a):
					break
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	A = [int(x) for x in input().split()]
	B = [0] * (n + 1)
	for j in range(n):
		c = A[j]
		for k in range(j + 1, n):
			c += A[k]
			if c <= n:
				B[c] = 1
	c = 0
	for j in range(n):
		if B[A[j]] == 1:
			c += 1
	print(c)


import os, sys, atexit
from io import BytesIO, StringIO
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
t = int(input())
while t:
	t += -1
	n = int(input())
	l = list(map(int, input().split()))
	cmsm = [l[0]]
	for i in range(1, n):
		cmsm.append(l[i] + cmsm[i - 1])
	cnt = [0] * (n + 1)
	for i in l:
		cnt[i] -= -1
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			if i > 0 and cmsm[j] - cmsm[i - 1] <= n:
				ans += cnt[cmsm[j] - cmsm[i - 1]]
				cnt[cmsm[j] - cmsm[i - 1]] = 0
			elif cmsm[j] <= n:
				ans += cnt[cmsm[j]]
				cnt[cmsm[j]] = 0
	print(ans)


T = int(input())
for t in range(T):
	n = int(input())
	cnt = 0
	arr = list(map(int, input().split()))
	exist = [0 for i in range(n + 1)]
	for i in range(n):
		exist[arr[i]] += 1
	for i in range(n):
		sm = arr[i]
		for j in range(i + 1, n):
			sm += arr[j]
			if sm <= n and exist[sm] >= 1:
				cnt += exist[sm]
				exist[sm] = 0
	print(cnt)


t = int(input())
for tests in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = dict()
	s = set()
	for i in range(n - 1):
		p = a[i]
		for j in range(i + 1, n):
			p += a[j]
			if p <= n:
				s.add(p)
			else:
				break
	r = list(set(a) & s)
	r.sort()
	real = dict()
	count = 0
	for i in a:
		if i in real:
			real[i] += 1
		else:
			real[i] = 1
	for i in r:
		count += real[i]
	print(count)


import collections
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ok = [0] * (n + 1)
	for l in range(n - 1):
		acum = arr[l]
		for r in range(l + 1, n):
			acum += arr[r]
			if acum > n:
				break
			ok[acum] = 1
	ans = 0
	for val in arr:
		if ok[val] == 1:
			ans += 1
	print(ans)


import sys
input = sys.stdin.readline
for nt in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for i in a:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	ans = 0
	for i in range(n):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s in d:
				ans += d[s]
				del d[s]
	print(ans)


import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

def gift():
	for _ in range(t):
		n = int(input())
		arrys = list(map(int, input().split()))
		ans = [0] * (n + 1)
		for i in range(n):
			now = arrys[i]
			for j in range(i + 1, n):
				now += arrys[j]
				if now <= n:
					ans[now] = True
		res = 0
		for i in range(n):
			if ans[arrys[i]]:
				res += 1
		yield res
t = int(input())
ans = gift()
print(*ans, sep='\n')


for _ in range(int(input())):
	d = {}
	n = int(input())
	l = list(map(int, input().split()))
	for t in l:
		if t not in d:
			d[t] = 1
		else:
			d[t] += 1
	ans = 0
	for i in range(n):
		sm = l[i]
		for j in range(i + 1, n):
			sm += l[j]
			if sm in d:
				ans += d[sm]
				d[sm] = 0
	print(ans)


tc = int(input())
for _ in range(tc):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	poss = [0 for _ in range(n + 1)]
	ans = 0
	lenn = len(arr)
	for i in range(lenn):
		x = arr[i]
		for j in range(i - 1, -1, -1):
			x += arr[j]
			if x > n:
				break
			poss[x] = 1
	for i in arr:
		if poss[i]:
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	pref = [0]
	for x in a:
		pref.append(pref[-1] + int(x))
	ans = 0
	for x in a:
		i = 1
		j = 1
		while i <= n and j <= n:
			temp = pref[j] - pref[i - 1]
			if i != j and temp == x:
				ans += 1
				break
			if temp < x:
				j += 1
			else:
				i += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	lst = [int(i) for i in input().split()]
	a = [0] * (n + 1)
	for i in range(n):
		s = lst[i]
		for j in range(i + 1, n):
			s += lst[j]
			if s <= n:
				a[s] = 1
			else:
				break
	print(sum([a[x] for x in lst]))


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = dict()
	for i in l:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	ans = 0
	for i in range(n):
		s = l[i]
		for j in range(i + 1, n):
			s += l[j]
			if s in d:
				ans += d[s]
				d[s] = 0
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = {}
	for i in a:
		c[i] = c.get(i, 0) + 1
	ans = 0
	for l in range(n):
		s = a[l]
		for r in range(l + 1, n):
			s += a[r]
			if s <= n:
				ans += c.get(s, 0)
				if c.get(s, 0) != 0:
					c[s] = 0
	print(ans)


from sys import stdin
from collections import deque
mod = 10 ** 9 + 7
import sys
import random
from queue import PriorityQueue
from bisect import bisect_right
from bisect import bisect_left
from collections import defaultdict
from math import sqrt, factorial, gcd, log2, inf, ceil
import heapq
input = lambda : sys.stdin.readline().rstrip()
from sys import stdin, stdout
from heapq import heapify, heappush, heappop
from itertools import permutations
from math import factorial as f

def ncr(n, r, p):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p
import sys
t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	hash = defaultdict(int)
	cnt = [0] * 8001
	for i in l:
		cnt[i] += 1
	ans = 0
	for i in range(n):
		sumi = l[i]
		for j in range(i + 1, n):
			sumi += l[j]
			try:
				ans += cnt[sumi]
				cnt[sumi] = 0
			except:
				pass
	print(ans)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
BUFSIZE = 8192
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def main():
	t = int(input())
	num = []
	for i in range(t):
		n = int(input())
		temp = list(map(int, input().split()))
		num.append(temp)
	for i in range(t):
		temp = num[i]
		ans = 0
		d = collections.Counter(temp)
		k = set(d.keys())
		if len(temp) <= 1:
			print(0)
			continue
		s = set()
		prefix = [0]
		for n in temp:
			prefix.append(n + prefix[-1])
		for i in range(len(prefix)):
			for j in range(i + 2, len(prefix)):
				m = prefix[j] - prefix[i]
				if m in k and m not in s:
					s.add(m)
					ans += d.get(m)
		print(ans)
main()


from collections import defaultdict
t = int(input())
while t > 0:
	t -= 1
	n = int(input())
	nums = list(map(int, input().split(' ')))
	d = defaultdict(int)
	for i in range(len(nums)):
		d[nums[i]] += 1
	ans = 0
	for i in range(len(nums)):
		sum_ = nums[i]
		for j in range(i + 1, len(nums)):
			sum_ += nums[j]
			if sum_ <= n:
				ans += d[sum_]
				d[sum_] = 0
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = (*map(int, input().split()),)
	ans = 0
	conta = [0] * n
	for e in a:
		conta[e - 1] += 1
	for i in range(n):
		tmp = a[i]
		while i + 1 < n >= tmp + a[i + 1]:
			i += 1
			tmp += a[i]
			ans += conta[tmp - 1]
			conta[tmp - 1] = 0
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	b = [0] * (n + 1)
	a = [int(v) for v in input().split()]
	s = 0
	c = 0
	for j in range(n):
		b[a[j]] += 1
	for j in range(n - 1):
		s = a[j]
		k = j + 1
		while k < n:
			s = s + a[k]
			if s > n:
				break
			elif b[s] > 0:
				c = c + b[s]
				b[s] = 0
			k = k + 1
	print(c)


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = defaultdict(int)
	maxi = max(a)
	for i in range(len(a) - 1):
		cnt = a[i]
		for j in range(i + 1, len(a)):
			cnt += a[j]
			if cnt > maxi:
				break
			b[cnt] = 1
	cnt = 0
	for i in a:
		if b[i] == 1:
			cnt += 1
	print(cnt)


import sys
input = sys.stdin.readline
from collections import defaultdict
(T,) = map(int, input().split())
for _ in range(T):
	d = defaultdict(int)
	(N,) = map(int, input().split())
	X = [0] * (N + 1)
	for (i, x) in enumerate(map(int, input().split())):
		X[i + 1] = X[i] + x
		d[x] += 1
	N += 1
	r = 0
	for i in range(N - 1):
		x = X[i]
		for j in range(i + 2, N):
			if X[j] - x in d:
				r += d[X[j] - x]
				del d[X[j] - x]
	print(r)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * (n + 1)
	ans = 0
	for i in range(n):
		b[a[i]] += 1
	for i in range(n):
		sum = 0
		for j in range(i, n):
			sum += a[j]
			if j == i:
				continue
			if sum <= n:
				ans += b[sum]
				b[sum] = 0
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * (n + 1)
	for i in range(n):
		c[a[i]] += 1
	ans = 0
	for i in range(n):
		sum = a[i]
		for j in range(i + 1, n):
			sum += a[j]
			if sum <= n:
				ans += c[sum]
				c[sum] = 0
			else:
				break
	print(ans)


import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def solve():
	n = ni()
	a = [0] + nl()
	ex = [0] * (n + 1)
	for i in range(n):
		a[i + 1] += a[i]
	for i in range(n - 1):
		for j in range(i + 2, n + 1):
			if a[j] - a[i] > n:
				break
			ex[a[j] - a[i]] = 1
	print(sum((ex[a[j + 1] - a[j]] for j in range(n))))
	return
T = ni()
for _ in range(T):
	solve()


import math
import sys
from collections import defaultdict, Counter, deque, OrderedDict
import bisect
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda : map(int, input().split())
alele = lambda : list(map(int, input().split()))

def list2d(a, b, c):
	return [[c] * b for i in range(a)]
from itertools import accumulate, groupby
import sys
for _ in range(int(input())):
	N = int(input())
	A = alele()
	count = 0
	C = [0] * (N + 1)
	for i in A:
		C[i] += 1
	for i in range(N):
		tot = 0
		for j in range(i, N):
			tot += A[j]
			if i != j and tot <= N:
				count += C[tot]
				C[tot] = 0
			if tot > N:
				break
	print(count)


from collections import Counter
import sys
t = int(sys.stdin.readline())
while t:
	n = int(sys.stdin.readline())
	arr = list(map(int, sys.stdin.readline().split()))
	d = Counter(arr)
	count = 0
	for i in range(n - 1):
		summ = arr[i]
		for j in range(i + 1, n):
			summ += arr[j]
			if summ in d:
				count += d[summ]
				d[summ] = 0
	print(count)
	t -= 1


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * (n + 1)
	ans = 0
	for i in range(n):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s > 0 and s <= n:
				c[s] += 1
	for i in range(n):
		ans += c[a[i]] > 0
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	sum = set()
	for i in range(n - 1):
		s = l[i]
		for i in range(i + 1, n):
			s += l[i]
			if s > n:
				break
			sum.add(s)
	ans = 0
	for i in l:
		if i in sum:
			ans += 1
	print(ans)


def solve(n, arr):
	exists = [0] * (n + 1)
	sumisthere = [False] * (n + 1)
	exists[arr[-1]] += 1
	for i in range(n - 1):
		exists[arr[i]] += 1
		s = arr[i]
		for j in range(i + 1, n):
			s += arr[j]
			if s > n:
				break
			sumisthere[s] = True
	return sum((e for (e, s) in zip(exists, sumisthere) if s))
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	print(solve(n, arr))


t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(p) for p in input().split()]
	preSum = [0, arr[0]]
	found = [0] * (max(arr) + 1)
	for i in range(1, n):
		preSum.append(preSum[-1] + arr[i])
	for i in range(n + 1):
		for j in range(i - 1):
			if preSum[i] - preSum[j] <= len(found) - 1:
				found[preSum[i] - preSum[j]] = 1
	cnt = 0
	for i in arr:
		if found[i]:
			cnt += 1
	print(cnt)


for s in [*open(0)][2::2]:
	a = (*map(int, s.split()),)
	n = len(a)
	b = [0] * (n + 1)
	r = 0
	for x in a:
		b[x] += 1
	for i in range(n):
		t = a[i]
		while i + 1 < n >= t + a[i + 1]:
			i += 1
			t += a[i]
			r += b[t]
			b[t] = 0
	print(r)


import collections
t = int(input())
for test in range(t):
	n = int(input())
	arr = input().split()
	p = [0]
	d = collections.defaultdict(int)
	for i in range(len(arr)):
		p.append(int(arr[i]) + p[i])
		d[int(arr[i])] += 1
	ans = 0
	s = set()
	for i in range(0, len(p) - 2):
		for j in range(i + 2, len(p)):
			if p[j] - p[i] in d and p[j] - p[i] not in s:
				s.add(p[j] - p[i])
				ans += d[p[j] - p[i]]
	print(ans)


import sys
import bisect
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	o = list(map(int, input().split()))
	ans = 0
	d = [0 for i in range(n + 1)]
	i = 0
	for i in o:
		d[i] += 1
	i = 0
	while i < n - 1:
		j = i + 1
		som = o[i]
		while j < n:
			som += o[j]
			if som < n + 1:
				ans += d[som]
				d[som] = 0
			j = j + 1
		i = i + 1
	sys.stdout.write(str(ans) + '\n')


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	c = 0
	l1 = []
	l2 = [0] * 8001
	for j in l:
		c += j
		l1.append(c)
	a = max(l)
	for j in range(1, n):
		if l1[j] > a:
			break
		l2[l1[j]] = 1
	for j in range(1, n):
		for k in range(j + 1, n):
			if l1[k] - l1[j - 1] > a:
				break
			l2[l1[k] - l1[j - 1]] = 1
	ans = 0
	for j in l:
		if l2[j] == 1:
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	seen = set()
	prev = [0]
	(cur, c) = (0, 0)
	for i in l:
		cur += i
		for j in range(len(prev) - 1):
			temp = cur - prev[j]
			if temp >= 1 and temp <= n:
				seen.add(cur - prev[j])
		prev.append(cur)
	for i in l:
		if i in seen:
			c += 1
	print(c)


from collections import Counter, defaultdict, deque
import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	arr = [int(x) for x in input().split()]
	c = defaultdict(int)
	mx = 0
	for el in arr:
		if el > mx:
			mx = el
		c[el] += 1
	res = 0
	for i in range(n):
		su = arr[i]
		p = i + 1
		while su <= mx and p < n:
			su += arr[p]
			if c[su]:
				res += c[su]
				c[su] = 0
			p += 1
	print(res)
tt = int(input())
for test in range(tt):
	solve()


from sys import stdin, stdout
from math import *

def bs(ar, l, r, req):
	ans = -1
	while l <= r:
		m = (l + r) // 2
		if ar[m] == req:
			return m
		elif ar[m] > req:
			r = m - 1
		else:
			l = m + 1
	return ans
for __ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	ans = 0
	pr = [0]
	a = {0: 0}
	for i in range(n):
		pr.append(pr[-1] + ar[i])
		a[pr[-1]] = i + 1
	d = {}
	rslt = 0
	for i in range(n):
		ans = -1
		if d.get(ar[i]) == -1:
			continue
		elif d.get(ar[i]) != None:
			rslt += 1
			continue
		for j in range(2, n + 1):
			c = pr[j]
			if c >= ar[i]:
				l = 0
				r = j
				req = c - ar[i]
				if a.get(req) != None:
					ans = a[req]
				if ans != -1 and j - ans > 1:
					break
				ans = -1
		if ans == -1:
			d[ar[i]] = -1
		else:
			d[ar[i]] = ans
			rslt += 1
	print(rslt)


from collections import Counter
for _ in ' ' * int(input()):
	n = int(input())
	a = list(map(int, input().split()))
	d = Counter(a)
	cnt = 0
	for i in range(n):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s in d:
				cnt += d[s]
				d[s] = 0
	print(cnt)


from collections import Counter
from sys import stdin, stdout
for testcases in range(int(stdin.readline())):
	n = int(stdin.readline())
	arr = list(map(int, stdin.readline().split()))
	count = Counter(arr)
	result = 0
	sum = 0
	for i in range(n - 1):
		sum = 0
		sum += arr[i] + arr[i + 1]
		result += count[sum]
		count[sum] = 0
		k = i + 2
		while sum <= n:
			if k >= n:
				break
			sum += arr[k]
			k += 1
			result += count[sum]
			count[sum] = 0
	stdout.write(str(result) + '\n')


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip().split()]

def st():
	return str(input().rstrip())[2:-1]

def val():
	return int(input().rstrip())

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(str(i)[2:-1]) for i in input().rstrip()]
for _ in range(val()):
	n = val()
	a = li()
	s = Counter(a)
	ans = 0
	for k in s:
		i = j = su = pos = 0
		while j < n:
			su += a[j]
			while su > k:
				su -= a[i]
				i += 1
			if su == k and j - i:
				pos = 1
				break
			j += 1
		ans += pos * s[k]
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	flag = [False] * (n + 1)
	for i in range(n):
		now = a[i]
		for j in range(i + 1, n):
			now += a[j]
			if now <= n:
				flag[now] = True
	ans = 0
	for ai in a:
		if flag[ai]:
			ans += 1
	print(ans)


MOD = 10 ** 9 + 7
INT_MAX = 10 ** 18 + 7

def INPUT():
	return list((int(i) for i in input().split()))

def LIST_1D_ARRAY(n):
	return [0 for _ in range(n)]

def LIST_2D_ARRAY(m, n):
	return [[0 for _ in range(n)] for _ in range(m)]

def power(a, x):
	res = 1
	while x > 0:
		if x & 1:
			res = res * a % MOD
		a = a * a % MOD
		x //= 2
	return res % MOD

def NCR_MOD(n, r):
	num = 1
	for i in range(n, n - r, -1):
		num = num * i % MOD
	for j in range(1, r + 1):
		num = num * power(j, MOD - 2) % MOD
	return num

def calc(n, A):
	cnt = [0 for i in range(8001)]
	for i in range(n):
		cnt[A[i]] += 1
	ans = 0
	for i in range(n):
		sum = 0
		for j in range(i, n):
			sum += A[j]
			if i == j:
				continue
			if sum <= 8000:
				ans += cnt[sum]
				cnt[sum] = 0
	return ans
for _ in range(int(input())):
	n = int(input())
	A = INPUT()
	print(calc(n, A))


from fractions import Fraction
import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
for _ in range(iinput()):
	n = iinput()
	a = rlinput()
	pref = list(accumulate(a))
	pref.insert(0, 0)
	ans = 0
	d = [0] * (n + 1)
	for i in a:
		d[i] += 1
	for i in range(1, n):
		for j in range(i + 1, n + 1):
			val = pref[j] - pref[i - 1]
			if val < n + 1 and d[val] != 0:
				ans += d[val]
				d[val] = 0
	print(ans)


from sys import stdin, stdout
from itertools import accumulate
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	s = set()
	a = list(map(int, stdin.readline().split()))
	for i in range(n):
		sm = a[i]
		for j in range(i + 1, n):
			sm += a[j]
			if sm > 8000:
				break
			s.add(sm)
	ans = 0
	for i in range(n):
		if a[i] in s:
			ans += 1
	print(ans)


def subArraySum(arr, n, sum):
	curr_sum = arr[0]
	start = 0
	i = 1
	while i <= n:
		while curr_sum > sum and start < i - 1:
			curr_sum = curr_sum - arr[start]
			start += 1
		if curr_sum == sum:
			if i - 1 - start >= 1:
				return True
		if i < n:
			curr_sum = curr_sum + arr[i]
		i += 1
	return False
for _ in range(int(input())):
	n = int(input())
	arr = [int(s) for s in input().split()]
	freq = {}
	for i in arr:
		if i in freq:
			freq[i] += 1
		else:
			freq[i] = 1
	temp = list(set(arr))
	count = 0
	for i in temp:
		if subArraySum(arr, n, i):
			count += freq[i]
	print(count)


import sys
t = int(sys.stdin.readline())
for T in range(t):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	s = set(a)
	yes = [0] * (n + 1)
	for i in range(n):
		acc = 0
		for j in range(i, n):
			acc += a[j]
			if i == j:
				continue
			if acc > n:
				break
			yes[acc] = 1
			s.discard(acc)
			if len(s) == 0:
				break
		if len(s) == 0:
			break
	ans = 0
	for i in range(n):
		if yes[a[i]] == 1:
			ans += 1
	print(ans)


cases = int(input())
for i in range(cases):
	n = int(input())
	l2 = input().split(' ')
	arr = []
	for a in l2:
		arr.append(int(a))
	d = {}
	for a in arr:
		if a in d:
			d[a] += 1
		else:
			d[a] = 1
	count = 0
	for j in range(len(arr)):
		ele1 = arr[j]
		for k in range(j + 1, len(arr)):
			ele2 = arr[k]
			ele1 += ele2
			if ele1 in d:
				count += d[ele1]
				del d[ele1]
	print(count)


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(stdin.readline())
		ar = list(map(int, input().split()))
		prefix = [0] * (n + 1)
		lookup = {}
		for i in range(n):
			if ar[i] not in lookup:
				lookup[ar[i]] = 1
			else:
				lookup[ar[i]] += 1
		ans = 0
		check = {key: False for key in lookup}
		for i in range(n):
			s = ar[i]
			for j in range(i + 1, n):
				s += ar[j]
				if s > n:
					break
				if s in lookup and (not check[s]):
					ans += lookup[s]
					check[s] = True
		print(ans)
main()


for _ in range(int(input())):
	value = int(input())
	s = input()
	a = (*map(int, s.split()),)
	n = len(a)
	b = 2 * n * [0]
	r = 0
	for x in a:
		b[x] += 1
	for i in range(n):
		t = a[i]
		while i + 1 < n >= t + a[i + 1]:
			i += 1
			t += a[i]
			r += b[t]
			b[t] = 0
	print(r)


from collections import defaultdict
for ii in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	q = set()
	for i in range(n - 1):
		w = arr[i]
		for j in range(i + 1, n):
			w += arr[j]
			if w > n:
				break
			q.add(w)
	for i in arr:
		if i in q:
			ans += 1
	print(ans)


from functools import reduce
from collections import Counter

def special(n, a):
	res = 0
	prefixSum = reduce(lambda l, x: l + [x + l[-1]], a, [0])
	(targets, maxA) = (Counter(a), max(a))
	for i in range(n):
		for j in range(i + 2, n + 1):
			s = prefixSum[j] - prefixSum[i]
			if s > maxA:
				break
			if s in targets:
				res += targets[s]
				targets.pop(s)
	return res

def solve():
	n = int(input())
	print(special(n, list(map(int, input().split()))))
for _ in range(int(input())):
	solve()


from collections import Counter
tests = int(input())
while tests:
	n = int(input())
	nums = [int(i) for i in input().split(' ')]
	freq = Counter(nums)
	ans = 0
	for l in range(n):
		sums = 0
		for r in range(l, n):
			sums += nums[r]
			if r == l:
				continue
			if sums <= n and sums in freq:
				ans += freq[sums]
				freq[sums] = 0
	print(ans)
	tests -= 1


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	co = 0
	a = []
	for i in range(n + 1):
		a.append(0)
	for i in range(n):
		su = l[i]
		for j in range(i + 1, n):
			su += l[j]
			if su > 0 and su <= n:
				a[su] += 1
	for i in range(n):
		co += a[l[i]] > 0
	print(co)


t = int(input())
for _ in range(t):
	input()
	arr = list(map(int, input().rstrip().split()))
	hashSum = {}
	for num in arr:
		if num not in hashSum:
			hashSum[num] = 1
		else:
			hashSum[num] += 1
	cnt = 0
	for pos in range(len(arr)):
		s = arr[pos]
		for pos2 in range(pos + 1, len(arr)):
			s += arr[pos2]
			if s in hashSum:
				cnt += hashSum[s]
				del hashSum[s]
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	A = [int(a) for a in input().split()]
	pr = [0] * (n + 1)
	for i in range(1, n + 1):
		pr[i] = pr[i - 1] + A[i - 1]
	C = [0] * (n + 1)
	for i in range(n):
		C[A[i]] += 1
	ans = 0
	for l in range(1, n + 1):
		for r in range(l + 1, n + 1):
			s = pr[r] - pr[l - 1]
			if s <= n:
				ans += C[s]
				C[s] = 0
	print(ans)


from sys import stdin, stdout

def s():
	t = int(stdin.readline())
	for _ in range(t):
		n = int(stdin.readline())
		arr = list(map(int, stdin.readline().split()))
		already = [0] * (n + 1)
		for x in arr:
			already[x] += 1
		res = 0
		for i in range(n):
			s = arr[i]
			for j in range(i + 1, n):
				s += arr[j]
				if s > n:
					continue
				if already[s] > 0:
					res += already[s]
					already[s] = 0
		stdout.write(str(res) + '\n')
s()


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return map(int, input().split())

def array():
	return [int(i) for i in input().split()]
for _ in range(int(input())):
	n = int(input())
	a = array()
	ans = set()
	ma = max(a)
	s = a[0]
	for i in range(1, n):
		s += a[i]
		if s <= ma:
			ans.add(s)
		k = 0
		for j in range(i - 1):
			k += a[j]
			if s - k <= ma:
				ans.add(s - k)
	c = 0
	for i in a:
		if i in ans:
			c += 1
	print(c)


from sys import stdin
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda : int(stdin.readline())
ip = lambda : [int(w) for w in stdin.readline().split()]
mp = lambda : map(int, input().split())
for _ in range(inp()):
	n = inp()
	x = ip()
	dt = {}
	for i in x:
		dt[i] = dt.get(i, 0) + 1
	vis = {}
	ans = 0
	for i in range(n - 1):
		t = x[i]
		for j in range(i + 1, n):
			t += x[j]
			if t in dt and (not vis.get(t, 0)):
				vis[t] = 1
				ans += dt[t]
	print(ans)


from itertools import accumulate
from collections import defaultdict
T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	cnt = defaultdict(int)
	Acum = [0] + list(accumulate(A))
	answer = 0
	max_A = max(A)
	for i in range(N):
		for j in range(i):
			if Acum[i + 1] - Acum[j] <= max_A:
				cnt[Acum[i + 1] - Acum[j]] = 1
	for i in range(N):
		if cnt[A[i]]:
			answer += 1
	print(answer)


for i in range(int(input())):
	n = int(input())
	w = list(map(int, input().split()))
	a = [0] * (n + 1)
	for i in range(n):
		cnt = w[i]
		for j in range(i + 1, n):
			cnt += w[j]
			if cnt > n:
				break
			a[cnt] = 1
	print(sum((a[i] for i in w)))


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = Counter(l)
	result = 0
	for i in range(n):
		s = l[i]
		for j in range(i + 1, n):
			s += l[j]
			if s in d:
				result += d[s]
				del d[s]
	print(result)


import sys
from collections import defaultdict
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def subarraySum(nums, k):
	if len(nums) < 2:
		return False
	hash_map = set()
	hash_map.add(0)
	total = 0
	for i in range(len(nums)):
		total += nums[i]
		if total - k in hash_map and nums[i] != k:
			return True
		hash_map.add(total)
	return False

def solve(arr):
	res = []
	for a in arr:
		count = [0] * (len(a) + 1)
		for i in a:
			count[i] += 1
		r = 0
		for i in range(len(a)):
			s = 0
			for j in range(i, len(a)):
				s += a[j]
				if i == j:
					continue
				if s <= len(a):
					r += count[s]
					count[s] = 0
		res.append(r)
	return res
t = inp()
arr = []
for i in range(t):
	inp()
	arr.append(inlt())
res = solve(arr)
for r in res:
	print(r)


t = int(input())
for i in range(t):
	n = int(input())
	arr = input()
	a = list(map(int, arr.split(' ')))
	special = 0
	for i in range(n):
		x = a[i]
		start = 0
		end = 0
		suma = a[0]
		while start <= end < n:
			if suma == x:
				if end != start:
					special += 1
					break
				else:
					start += 1
					end += 1
					if start < n:
						suma = a[start]
					else:
						break
			elif suma < x:
				end += 1
				if end < n:
					suma += a[end]
			else:
				suma -= a[start]
				start += 1
				if start > end:
					end += 1
					if end == n:
						break
					suma += a[end]
	print(special)


from collections import defaultdict
for T in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	d = defaultdict(int)
	for i in range(n):
		d[arr[i]] += 1
	count = 0
	for i in range(n - 1):
		temp = arr[i]
		for j in range(i + 1, n):
			temp += arr[j]
			if d.get(temp, 0):
				count += d[temp]
				d[temp] = 0
	print(count)


def read_int():
	return int(input())

def read_int_n():
	return list(map(int, input().split()))
from collections import Counter

def slv(N, A):
	c = Counter(A)
	h = set()
	for i in range(N):
		t = A[i]
		for j in range(i + 1, N):
			t += A[j]
			if t in c:
				h.add(t)
	return sum((c[k] for k in h))

def main():
	T = read_int()
	for _ in range(T):
		N = read_int()
		A = read_int_n()
		print(slv(N, A))
main()


from collections import defaultdict
for _ in range(int(input())):
	_ = input()
	l = list(map(int, input().split()))
	prefixSums = [0]
	count = defaultdict(int)
	for i in range(len(l)):
		prefixSums.append(prefixSums[-1] + l[i])
		count[l[i]] += 1
	res = 0
	for i in range(len(prefixSums)):
		for j in range(i + 2, len(prefixSums)):
			x = prefixSums[j] - prefixSums[i]
			if x in count:
				res += count[x]
				del count[x]
	print(res)


import math

def r():
	return map(int, input().split())

def l():
	return list(map(int, input().split()))

def i():
	return int(input())

def si():
	return input()

def pYes():
	print('YES')

def pNo():
	print('NO')

def plist(l):
	print(''.join(l))
t = int(input())
for t1 in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	p = [0] * 8001
	for i in range(n):
		a1 = a[i]
		for j in range(i + 1, n):
			a1 += a[j]
			if a1 < 8001:
				p[a1] = 1
	for i in a:
		cnt += p[i]
	print(cnt)


t = int(input())
for i in range(t):
	n = int(input())
	b = list(map(int, input().split()))
	d = dict()
	e = dict()
	for j in range(n):
		if b[j] in d.keys():
			d[b[j]] += 1
		else:
			d[b[j]] = 1
	for i in range(0, n):
		temp = b[i]
		for j in range(i + 1, n):
			temp += b[j]
			if temp > n:
				break
			e[temp] = 1
	c = list(set(b))
	p = 0
	for j in c:
		if j in e.keys():
			p += d[j]
	print(p)


from collections import Counter
t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	presum = [0]
	for i in range(n):
		presum.append(presum[-1] + a[i])
	s = [0 for _ in range(n + 1)]
	for i in range(n - 1):
		for j in range(i + 2, n + 1):
			index = presum[j] - presum[i]
			if index <= n:
				s[index] = 1
	c = Counter(a)
	ans = 0
	for ai in c:
		if s[ai]:
			ans += c[ai]
	print(ans)


from collections import Counter
for _ in range(int(input())):
	(n, ans) = (int(input()), 0)
	arr = list(map(int, input().split()))
	cnt = Counter(arr)
	for i in range(n - 1):
		cur = arr[i]
		for j in range(i + 1, n):
			cur += arr[j]
			if cnt[cur]:
				ans += cnt[cur]
				del cnt[cur]
	print(ans)


def main():
	import sys, math
	from heapq import heapify, heappush, heappop
	from collections import defaultdict as dd, deque

	def data():
		return sys.stdin.buffer.readline().strip()

	def mdata():
		return list(map(int, data().split()))
	INF = int(1000000000.0)
	mod = int(1000000000.0) + 7
	ans = []
	for t in range(int(data())):
		n = int(data())
		A = mdata()
		cnt = 0
		s = set()
		for i in range(n):
			a = A[i]
			for j in range(i + 1, n):
				a += A[j]
				if a > n:
					break
				s.add(a)
		cnt = 0
		for i in A:
			if i in s:
				cnt += 1
		ans.append(str(cnt))
	sys.stdout.write('\n'.join(ans))
main()


tests = int(input())
for test in range(tests):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0]
	for x in a:
		b.append(x + b[-1])
	was = [0] * (n + 1)
	for i in range(n):
		for j in range(i + 1, n):
			if b[j + 1] - b[i] <= n:
				was[b[j + 1] - b[i]] = 1
	ans = 0
	for x in a:
		ans += was[x]
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	pref = [0]
	for v in l:
		pref.append(pref[-1] + v)
	seen = dict()
	for v in l:
		if v not in seen:
			seen[v] = 0
		seen[v] += 1
	count = 0
	for i in range(n + 1):
		for j in range(i + 2, n + 1):
			nex = pref[j] - pref[i]
			if nex in seen:
				count += seen[nex]
				del seen[nex]
	print(count)


import os
import sys
import math
from io import BytesIO, IOBase
input = sys.stdin.readline

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def dijkstra(start, distance, path, n):
	visited = [False for _ in range(n)]
	distance[start] = 0
	for i in range(n):
		v = -1
		for j in range(n):
			if not visited[v] and (v == -1 or distance[j] < distance[v]):
				v = j
		if distance[v] == math.inf:
			break
		visited[v] = True
		for edge in adj[v]:
			destination = edge[0]
			weight = edge[1]
			if distance[v] + weight < distance[destination]:
				distance[destination] = distance[v] + weight
				path[destination] = v

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def ncr(n, r):
	return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def npr(n, r):
	return math.factorial(n) // math.factorial(n - r)

def seive(n):
	primes = [True] * (n + 1)
	ans = []
	for i in range(2, n):
		if not primes[i]:
			continue
		j = 2 * i
		while j <= n:
			primes[j] = False
			j += i
	for p in range(2, n + 1):
		if primes[p]:
			ans += [p]
	return ans

def factors(n):
	factors = []
	x = 1
	while x * x <= n:
		if n % x == 0:
			if n // x == x:
				factors.append(x)
			else:
				factors.append(x)
				factors.append(n // x)
		x += 1
	return factors

def main():
	try:
		for _ in range(inp()):
			n = inp()
			a = inlt()
			s = set()
			m = max(a)
			for i in range(n):
				c = a[i]
				for j in range(i + 1, n):
					c += a[j]
					if c <= m:
						s.add(c)
					else:
						break
			ans = 0
			for i in range(n):
				if a[i] in s:
					ans += 1
			print(ans)
	except Exception as e:
		print(e)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


T = int(input())
for _ in range(T):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	prefix = []
	prefix.append(arr[0])
	mx = arr[0]
	for i in range(1, n):
		mx = max(mx, arr[i])
		prefix.append(arr[i])
		prefix[i] += prefix[i - 1]
	m = {}
	for i in range(0, n):
		for j in range(i + 1, n):
			if i == 0:
				s = prefix[j]
				if s <= mx:
					m[s] = 0
			else:
				s = prefix[j] - prefix[i - 1]
				if s <= mx:
					m[s] = 0
	ans = 0
	for i in arr:
		if i in m:
			ans += 1
	print(ans)


mark = [False] * 8002
special = [False] * 8002
for i in range(int(input())):
	(n, a) = (int(input()), list(map(int, input().split(' '))))
	for x in a:
		mark[x] = True
	sum = 0
	for st in range(n):
		sum = a[st]
		for en in range(st + 1, n):
			sum += a[en]
			if sum > 8000:
				break
			if mark[sum]:
				special[sum] = True
	ans = 0
	for x in a:
		if special[x]:
			ans += 1
	for i in range(8002):
		mark[i] = False
		special[i] = False
	print(ans)


def solve(arr):
	s = set()
	psum = [0]
	mx = max(arr)
	for n in arr:
		psum.append(psum[-1] + n)
	for i in range(len(psum)):
		for j in range(i + 2, len(psum)):
			if psum[j] - psum[i] > mx:
				break
			s.add(psum[j] - psum[i])
	res = 0
	for n in arr:
		if n in s:
			res += 1
	print(res)
T = int(input())
for ti in range(1, T + 1):
	size = int(input())
	arr = list(map(int, input().split(' ')))
	solve(arr)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = Counter(a)
	c = list(a)
	for i in range(1, n):
		c[i] += c[i - 1]
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			v = c[j] - c[i] + a[i]
			if v in b:
				ans += b[v]
				b.pop(v)
	print(ans)


from collections import Counter
from collections import deque

def subArraySum(arr, n, sum):
	curr_sum = arr[0]
	start = 0
	i = 1
	while i <= n:
		while curr_sum > sum and start < i - 1:
			curr_sum = curr_sum - arr[start]
			start += 1
		if curr_sum == sum:
			if i - 1 - start != 0:
				return 1
		if i < n:
			curr_sum = curr_sum + arr[i]
		i += 1
	return 0
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	s = set(l)
	c = Counter(l)
	count = 0
	for i in s:
		if subArraySum(l, len(l), i):
			count += c[i]
	print(count)


import array
tcs = int(input())
for tc in range(tcs):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = [0] * (n + 1)
	ans = 0
	for i in range(n):
		cnt[a[i]] += 1
	for l in range(n):
		s = 0
		for r in range(l, n):
			s += a[r]
			if r == l:
				continue
			if s <= n:
				ans += cnt[s]
				cnt[s] = 0
	print(ans)


from sys import stdin

def main():
	readline = stdin.readline
	t = int(readline())
	for i in range(t):
		n = int(readline())
		a = list(map(int, readline().split()))
		s = [0] * n
		s[0] = a[0]
		for j in range(1, n):
			s[j] = s[j - 1] + a[j]
		s.insert(0, 0)
		nums = [False] * 8001
		for j in range(n - 1):
			for k in range(j + 2, n + 1):
				if s[k] - s[j] <= 8000:
					nums[s[k] - s[j]] = True
		ans = 0
		for j in range(n):
			if nums[a[j]]:
				ans += 1
		print(ans)
main()


import sys
import math

def inputnum():
	return int(input())

def inputnums():
	return map(int, input().split())

def inputlist():
	return list(map(int, input().split()))

def inputstring():
	return [x for x in input()]
t = int(input())
for q in range(t):
	n = inputnum()
	a = inputlist()
	b = [0] * n
	for i in range(n):
		b[i] = a[i]
	for i in range(1, n):
		a[i] += a[i - 1]
	sums = [0] * 9000
	for i in range(1, n):
		if a[i] <= 8000:
			sums[a[i]] += 1
		j = i - 2
		while j >= 0:
			if a[i] - a[j] <= 8000:
				sums[a[i] - a[j]] += 1
				j -= 1
			else:
				break
	ans = 0
	for i in range(n):
		if sums[b[i]] != 0:
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = [0]
	for x in a:
		s.append(x + s[len(s) - 1])
	res = 0
	for x in a:
		j = 2
		for i in range(len(s)):
			if j < i + 2:
				j = i + 2
			while j < len(s) and s[j] < s[i] + x:
				j += 1
			if j < len(s) and s[j] == s[i] + x:
				res += 1
				break
	print(res)


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout

def main():
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	for _ in range(ri()):
		n = ri()
		a = ria()
		cs = [0]
		yo = [0] * 8001
		currsum = 0
		for i in range(n):
			currsum += a[i]
			cs.append(currsum)
		ans = 0
		for i in range(1, n):
			for j in range(i + 1, n + 1):
				if cs[j] - cs[i - 1] <= 8000:
					yo[cs[j] - cs[i - 1]] += 1
		for i in a:
			if yo[i] > 0:
				ans += 1
		print(ans)
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
cases = int(input())
for t in range(cases):
	n = int(input())
	b = [0] + list(map(int, input().split()))
	d = {}
	for i in range(n):
		if b[i + 1] in d:
			d[b[i + 1]] += 1
		else:
			d[b[i + 1]] = 1
		b[i + 1] += b[i]
	s = 0
	d1 = set()
	for i in range(n - 1):
		for j in range(i + 2, n + 1):
			v = b[j] - b[i]
			if v in d:
				d1.add(v)
	for i in d1:
		s += d[i]
	print(s)


for _ in range(int(input())):
	n = int(input())
	res = []
	cnt = [0] * (n + 1)
	for i in map(int, input().split()):
		cnt[i] += 1
		res.append(i)
	ans = 0
	for i in range(n):
		sum1 = 0
		for j in range(i, n):
			sum1 += res[j]
			if j == i:
				continue
			if sum1 <= n:
				ans += cnt[sum1]
				cnt[sum1] = 0
			else:
				break
	print(ans)


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
for _ in range(int(input())):
	n = int(input())
	mp = defaultdict(int)
	a = list(mapi())
	b = []
	for i in a:
		mp[i] += 1
	b = list(set(a))
	res = 0
	for i in range(len(b) - 1, -1, -1):
		sm = b[i]
		cur = a[0]
		s = 0
		f = 0
		for j in range(1, n + 1):
			while cur > sm and s < j - 1:
				cur = cur - a[s]
				s += 1
			if cur == sm:
				if abs(s - j + 1) >= 1:
					f = 1
					break
			if j < n:
				cur = cur + a[j]
		if f:
			res += mp[b[i]]
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	l = []
	c = 0
	d = [0 for i in range(max(arr) + 1)]
	se = set(arr)
	for i in arr:
		d[i] += 1
	for i in range(n - 1):
		s = arr[i]
		for j in range(i + 1, n):
			s += arr[j]
			if s in se and d[s] > 0:
				c += d[s]
				d[s] = 0
	print(c)


T = int(input())
while T > 0:
	N = int(input())
	d = [int(x) for x in input().split()]
	L = [0] * N
	R = [0] * N
	m = [0] * (N + 1)
	for i in range(N):
		m[d[i]] += 1
	s = 0
	for i in range(N):
		L[i] = s
		s += d[i]
	ss = 0
	for i in range(N):
		R[i] = ss
		ss += d[N - i - 1]
	count = 0
	for i in range(N):
		for j in range(N):
			if i + j + 1 < N:
				x = s - L[i] - R[j]
				if x <= N and m[x] > 0:
					count += m[x]
					m[x] = 0
	print(count)
	T -= 1


t = int(input())
while t > 0:
	n = int(input())
	arr = [0] + [int(x) for x in input().split(' ')]
	summ = [0] * 8001
	si = 0
	sj = 0
	for i in range(n + 1):
		si += arr[i]
		sj = 0
		for j in range(i + 1):
			sj += arr[j]
			if i - j >= 2 and si - sj <= 8000:
				summ[si - sj] = 1
	ans = 0
	for i in arr:
		ans += summ[i]
	print(ans)
	t -= 1


from collections import defaultdict

def special_element(a, val):
	j = 0
	total_sum = 0
	for i in range(len(a)):
		total_sum += a[i]
		while total_sum >= val and j < len(a):
			if total_sum == val and i - j >= 1:
				return True
			else:
				total_sum -= a[j]
				j += 1
	return False
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	special_elements = 0
	visited = defaultdict(bool)
	special = defaultdict(bool)
	for i in range(n):
		if visited[arr[i]] == False:
			visited[arr[i]] = True
			part1 = arr[:i]
			part2 = arr[i + 1:]
			value = arr[i]
			if special_element(part1, value) or special_element(part2, value):
				special_elements += 1
				special[arr[i]] = True
		elif special[arr[i]] == True:
			special_elements += 1
	print(special_elements)


from collections import Counter

def subArraySum(arr, n, sum):
	curr_sum = arr[0]
	count = 1
	start = 0
	i = 1
	while i <= n:
		while curr_sum > sum and start < i - 1:
			curr_sum = curr_sum - arr[start]
			count -= 1
			start += 1
		if curr_sum == sum and count > 1:
			return 1
		if i < n:
			curr_sum = curr_sum + arr[i]
			count += 1
		i += 1
	return 0
for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = set(a)
	co = Counter(a)
	c = 0
	for i in s:
		if subArraySum(a, n, i):
			c += co[i]
	print(c)


t = int(input())
for tt in range(t):
	n = int(input())
	a = [*map(int, input().split())]
	b = [0] * (n + 1)
	for i in range(n - 1):
		cur = a[i]
		for j in range(i + 1, n):
			cur += a[j]
			if cur > n:
				break
			b[cur] = 1
	print(sum((b[e] for e in a)))


import sys
from math import ceil
read = sys.stdin.buffer.readline
mi = lambda : map(int, read().split())
li = lambda : list(mi())
cin = lambda : int(read())
for _ in range(cin()):
	n = cin()
	a = li()
	freq = [0] * (n + 1)
	for el in a:
		freq[el] += 1
	ans = 0
	for i in range(n - 1):
		sm = a[i]
		for j in range(i + 1, n):
			sm += a[j]
			if sm <= n and freq[sm] > 0:
				ans += freq[sm]
				freq[sm] = 0
	print(ans)


for i in range(int(input())):
	input()
	arr = list(map(int, input().split()))
	ans = 0
	quant = list((0 for j in range(len(arr))))
	for j in arr:
		quant[j - 1] += 1
	for j in range(len(arr)):
		now = 0
		for h in range(j, len(arr)):
			now += arr[h]
			if now > len(arr):
				break
			if j != h:
				ans += quant[now - 1]
				quant[now - 1] = 0
	print(ans)


import math
for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	ans = [0] * (n + 1)
	s = 0
	for i in range(n):
		s = l[i]
		for j in range(i + 1, n):
			s += l[j]
			if s > 0 and s <= n:
				ans[s] += 1
	a = 0
	for i in range(n):
		a += ans[l[i]] > 0
	print(a)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	mx = max(a)
	su = [0]
	for j in range(n):
		x = su[-1] + a[j]
		su.append(x)
	su = su[1:]
	vals = set(su[1:])
	for j in range(n):
		for k in range(j + 2, n):
			v = su[k] - su[j]
			if v > mx:
				break
			vals.add(su[k] - su[j])
	res = []
	for j in range(n):
		if a[j] in vals:
			res.append(a[j])
	print(len(res))


class SummedRange:

	def __init__(self, arr):
		self.arr = arr
		self.psums = [0]
		for num in arr:
			self.psums.append(self.psums[-1] + num)

	def sum(self, i, j):
		return self.psums[j] - self.psums[i]

def brute(n, a):
	result = 0
	for x in a:
		found = False
		for l in range(len(a)):
			for r in range(l + 2, len(a) + 1):
				if sum(a[l:r]) == x:
					result += 1
					found = True
					break
			if found:
				break
	return result

def soln(n, a):
	p = SummedRange(a)
	result = 0
	seen = set([])
	for l in range(len(a)):
		for r in range(l + 2, len(a) + 1):
			curr = p.sum(l, r)
			if curr <= n:
				seen.add(curr)
	for x in a:
		if x in seen:
			result += 1
	return result

def main():
	t = int(input())
	for _ in range(t):
		n = int(input())
		a = [int(x) for x in input().split()]
		result = soln(n, a)
		print(result)
main()


from collections import Counter
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = Counter(a)
	cs = [0]
	m = max(a)
	ans = 0
	for x in a:
		cs.append(cs[-1] + x)
	sec = set()
	for i in range(n):
		for j in range(i + 2, n + 1):
			temp = cs[j] - cs[i]
			if temp <= m:
				sec.add(temp)
			else:
				break
	for x in c.items():
		if x[0] in sec:
			ans += x[1]
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	al = list(map(int, input().split()))
	cnt = [0] * (n + 1)
	for i in range(len(al)):
		cnt[al[i]] += 1
	ans = 0
	for l in range(n):
		su = 0
		for r in range(l, n):
			su += al[r]
			if l == r:
				continue
			if su <= n:
				ans += cnt[su]
				cnt[su] = 0
	print(ans)


from sys import stdin

def solve(n, a):
	d = [0] * (n + 1)
	for i in range(1, n + 1):
		d[i] = d[i - 1] + a[i - 1]
	h = [0] * (n + 1)
	for i in range(1, n):
		for j in range(i + 1, n + 1):
			s = d[j] - d[i - 1]
			if s > 0 and s <= n:
				h[s] = 1
	ans = 0
	for i in a:
		if h[i] == 1:
			ans += 1
	print(ans)

def main():
	inp = stdin.readline
	for _ in range(int(inp())):
		n = int(inp())
		a = list(map(int, inp().split()))
		solve(n, a)
main()


from sys import stdin

def inp():
	return stdin.buffer.readline().rstrip().decode('utf8')

def itg():
	return int(stdin.buffer.readline())

def mpint():
	return map(int, stdin.buffer.readline().split())
from itertools import accumulate
from operator import add

class Query:

	def __init__(self, seq, func=add):
		self._data = seq
		self.prefix = tuple(accumulate(self._data, func=func))

	def __getitem__(self, item):
		if isinstance(item, int):
			return self._data[item]
		if isinstance(item, slice):
			start = 0 if item.start is None else item.start
			stop = len(self._data) if item.stop is None else item.stop
			if stop == 0:
				return 0
			if start == 0:
				return self.prefix[stop - 1]
			return self.prefix[stop - 1] - self.prefix[start - 1]
from collections import defaultdict
for case in range(itg()):
	n = itg()
	arr = tuple(mpint())
	query = Query(arr)
	cnt = defaultdict(int)
	for num in arr:
		cnt[num] += 1
	st = set(arr)
	size = len(st)
	ans = 0
	for i in range(n - 1):
		for j in range(i + 2, n + 1):
			sm = query[i:j]
			if sm in st:
				st.remove(sm)
				ans += cnt[sm]
				if not st:
					break
		else:
			continue
		break
	print(ans)


t = int(input())
while t > 0:
	n = int(input())
	l = list(map(int, input().split()))
	x = max(l)
	m = [0] * (x + 1)
	for i in l:
		m[i] += 1
	c = 0
	for i in range(n - 1):
		s = l[i]
		for j in range(i + 1, n):
			s += l[j]
			if s > x:
				break
			c += m[s]
			m[s] = 0
			if c >= n:
				break
		if c >= n:
			break
	print(c)
	t -= 1


from sys import stdin
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	is_special = [0] * (n + 1)
	for i in range(n):
		cur = a[i]
		for j in range(i + 1, n):
			cur += a[j]
			if cur > n:
				break
			is_special[cur] = 1
	res = 0
	for i in a:
		res += is_special[i]
	print(res)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	special = [0] * (2 * n)
	for i in range(n - 1):
		summ = a[i]
		j = i + 1
		while j < n and summ < n:
			summ += a[j]
			j += 1
			special[summ] = 1
	cnt_spec = 0
	for i in range(n):
		cnt_spec += special[a[i]]
	print(cnt_spec)


t = int(input())
for you in range(t):
	n = int(input())
	l = input().split()
	li = [int(i) for i in l]
	arr = [0 for i in range(n)]
	visited = [0 for i in range(n)]
	for i in li:
		arr[i - 1] += 1
	pref = [0]
	sumi = 0
	for i in range(n):
		sumi += li[i]
		pref.append(sumi)
	count = 0
	for i in range(n + 1):
		for j in range(i + 2, n + 1):
			x = pref[j] - pref[i]
			if x <= n and x > 0:
				if visited[x - 1] == 0:
					count += arr[x - 1]
					visited[x - 1] = 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = [0] * n
	s[0] = a[0]
	for k in range(1, n):
		s[k] = a[k] + s[k - 1]
	t = set()
	s = [0] + s
	for l in range(2, n + 1):
		for k in range(n - l + 1):
			if s[k + l] - s[k] <= n:
				t.add(s[k + l] - s[k])
	ans = 0
	for e in a:
		if e in t:
			ans += 1
	print(ans)


import sys
ints = (int(x) for x in sys.stdin.read().split())
sys.setrecursionlimit(3000)

def main():
	ntc = next(ints)
	for tc in range(ntc):
		n = next(ints)
		a = [next(ints) for i in range(n)]
		s = set()
		for l in range(n):
			x = a[l]
			for r in range(l + 1, n):
				x += a[r]
				if x > n:
					break
				s.add(x)
		print(sum((x in s for x in a)))
	return
main()


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	d = {}
	for i in arr:
		if i in d.keys():
			d[i] += 1
		else:
			d[i] = 1
	k = 0
	for i in range(n - 1):
		s = arr[i]
		for j in range(i + 1, n):
			s += arr[j]
			if s in d.keys():
				k += d[s]
				d[s] = 0
	print(k)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = input().split(' ')
	d = {}
	for i in range(n):
		a[i] = int(a[i])
		if a[i] not in d:
			d[a[i]] = 1
		else:
			d[a[i]] += 1
	sum = []
	s = 0
	for i in range(n):
		s += a[i]
		sum.append(s)
	sum.append(s)
	xx = {}
	co = 0
	for i in range(n):
		for j in range(i + 1, n):
			if i == 0:
				if sum[j] in d:
					if sum[j] not in xx:
						xx[sum[j]] = 1
						co += d[sum[j]]
			elif sum[j] - sum[i - 1] in d:
				if sum[j] - sum[i - 1] not in xx:
					xx[sum[j] - sum[i - 1]] = 1
					co += d[sum[j] - sum[i - 1]]
	print(co)


def solution(t):
	for _ in range(t):
		n = int(input())
		a = tuple(map(int, input().split()))
		b = [0] * 8001
		c = 0
		for (i, ai) in enumerate(a):
			for j in range(i + 1, n):
				ai += a[j]
				if ai > n:
					break
				b[ai] = 1
		for i in a:
			if b[i]:
				c += 1
		print(c)
solution(int(input()))


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	k = max(a)
	b = [0] * (k + 1)
	l = set()
	for i in range(n):
		s = a[i]
		for j in range(i + 1, n):
			s = s + a[j]
			if s <= k:
				l.add(s)
			else:
				break
	c = 0
	for i in a:
		b[i] = b[i] + 1
	for i in l:
		c = c + b[i]
	print(c)


t = int(input())
while t > 0:
	n = int(input())
	arr = [int(x) for x in input().split()]
	has = [0] * (n + 1)
	for i in range(n):
		sum = arr[i]
		for j in range(i + 1, n):
			sum += arr[j]
			if sum > n:
				break
			else:
				has[sum] = 1 + has[sum]
	ans = 0
	for i in range(n):
		if has[arr[i]] > 0:
			ans = 1 + ans
	print(ans)
	t -= 1


import sys, math
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	n = inp()
	ara = inara()
	fre = [0] * (n + 2)
	special = set()
	for i in range(n):
		tot = ara[i]
		fre[ara[i]] += 1
		for j in range(i + 1, n):
			tot += ara[j]
			if tot <= n:
				special.add(tot)
	ans = 0
	for element in special:
		ans += fre[element]
	print(ans)


def Zs():
	return list(map(int, input().split()))

def Z():
	return int(input())

def solve(N, A):
	s = [0] * (N + 1)
	for i in range(N):
		s[i + 1] = s[i] + A[i]
	aru = [False] * (N + 1)
	for i in range(N):
		for j in range(i + 1, N):
			if s[j + 1] - s[i] <= N:
				aru[s[j + 1] - s[i]] = True
	ans = 0
	for i in range(N):
		if aru[A[i]]:
			ans += 1
	return ans
for _ in range(Z()):
	N = Z()
	A = Zs()
	print(solve(N, A))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().strip().split()))
	b = [0] * (n + 1)
	for i in range(n):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s > n:
				break
			b[s] = 1
	ans = sum((1 for i in a if b[i]))
	print(ans)


tc = int(input())
for _ in range(tc):
	n = int(input())
	a = list(map(int, input().split()))
	present = [0 for _ in range(n + 1)]
	is_seg_sum = [0 for _ in range(n + 1)]
	for i in range(n):
		present[a[i]] += 1
	for i in range(n):
		seg_sum = a[i]
		for j in range(i + 1, n):
			seg_sum += a[j]
			if seg_sum > n:
				break
			is_seg_sum[seg_sum] = 1
	ans = 0
	for i in range(1, n + 1):
		if is_seg_sum[i] == 1:
			ans += present[i]
	print(ans)


from collections import Counter
t = int(input())
ns = []
aall = []
for _ in range(t):
	n = int(input())
	ns.append(n)
	a = list(map(int, input().split()))
	aall.append(a)
for i in range(t):
	n = ns[i]
	a = aall[i]
	c = Counter(a)
	ans = 0
	for j in range(n - 1):
		tmp = a[j]
		for k in range(j + 1, n):
			tmp += a[k]
			if tmp in c:
				ans += c[tmp]
				del c[tmp]
	print(ans)


t = int(input())
for k in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	for i in l:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	res = 0
	for i in range(n):
		s = l[i]
		for j in range(i + 1, n):
			s += l[j]
			if s in d:
				res += d[s]
				d[s] = 0
	print(res)


for _ in range(int(input())):
	n = int(input())
	aa = list(map(int, input().split()))
	ans = {i: False for i in aa}
	for i in range(n):
		now = aa[i]
		for j in range(i + 1, n):
			now += aa[j]
			if now > n:
				break
			if now in ans:
				ans[now] = True
	res = 0
	for i in aa:
		res += 1 if ans[i] else 0
	print(res)


def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		A = list(map(int, input().split()))
		if N == 1:
			print(0)
			continue
		ans = 0
		for i in range(N):
			j = 2
			curr_summ = A[0] + A[1]
			start = 0
			while j <= N:
				while curr_summ > A[i] and start < j - 2:
					curr_summ -= A[start]
					start += 1
				if curr_summ == A[i]:
					ans += 1
					break
				if j < N:
					curr_summ = curr_summ + A[j]
				j += 1
		print(ans)
main()


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l.insert(0, 0)
	n += 1
	maxi = max(l)
	prefix = [0] * n
	d = dict()
	for i in range(1, n):
		prefix[i] = prefix[i - 1] + l[i]
		if l[i] not in d:
			d[l[i]] = 0
		d[l[i]] += 1
	ans = 0
	for i in range(n - 2):
		for j in range(i + 2, n):
			if prefix[j] - prefix[i] > maxi:
				break
			if prefix[j] - prefix[i] in d:
				ans += d[prefix[j] - prefix[i]]
				d[prefix[j] - prefix[i]] = 0
	print(ans)


import sys
import bisect
import heapq
from math import *
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
mod = pow(10, 9) + 7

def inp():
	return sys.stdin.readline().strip()

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def graph(vertex):
	return [[] for i in range(0, vertex + 1)]

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def solve():
	n = int(inp())
	a = lis()
	m = max(a)
	ans = [0] * (m + 1)
	for i in range(0, n):
		sum = a[i]
		for j in range(i + 1, n):
			sum += a[j]
			if sum > m:
				break
			else:
				ans[sum] += 1
	cnt = 0
	for i in range(0, n):
		if ans[a[i]] > 0:
			cnt += 1
	print(cnt)
testcase(int(inp()))


import itertools as it
t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	counter = [0] * n
	for ai in a:
		counter[ai - 1] += 1
	found_sum = [False] * n
	for i in range(n):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s > n:
				break
			found_sum[s - 1] = True
	res = sum(map(counter.__getitem__, it.compress(range(n), found_sum)))
	print(res)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	se = [0] * (n + 1)
	if n == 1:
		print(0)
	elif n == 2:
		count = 0
		if ar[0] == sum(ar):
			count += 1
		if ar[1] == sum(ar):
			count += 1
		print(count)
	else:
		for i in range(2, n + 1):
			su = 0
			for j in range(i):
				su += ar[j]
			if su <= n and se[su] == 0:
				se[su] = 1
			for j in range(i, n):
				su += ar[j] - ar[j - i]
				if su <= n and se[su] == 0:
					se[su] = 1
		count = 0
		for i in ar:
			if se[i] == 1:
				count += 1
		print(count)


def sovle(a):
	special = [False] * (len(a) + 1)
	sums = [0]
	for i in a:
		sums.append(sums[-1] + i)
	for i in range(len(a)):
		for j in range(i + 2, len(a) + 1):
			if sums[j] - sums[i] > len(a):
				break
			special[sums[j] - sums[i]] = True
	return sum(map(lambda x: special[x], a))
for i in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	print(sovle(a))


from collections import Counter
t = int(input())
for i in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	arre = arr[:]
	c = Counter(arre)
	count = 0
	flag = 0
	for j in range(n - 1):
		sume = arr[j]
		for k in range(j, n - 1):
			sume += arr[k + 1]
			if sume > n:
				break
			if sume in c:
				count += c[sume]
				del c[sume]
			if not c:
				flag = 1
				break
		if flag == 1:
			break
	print(count)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	freq = {}
	for i in arr:
		freq[i] = freq.get(i, 0) + 1
	ans = 0
	for key in freq:
		s = 0
		i = 0
		j = 0
		while j < n:
			s = s + arr[j]
			if s == key and j - i + 1 > 1:
				ans = ans + max(0, freq[key])
				freq[key] = 0
			while s > key:
				s = s - arr[i]
				i = i + 1
				if s == key and j - i + 1 > 1:
					ans = ans + max(0, freq[key])
					freq[key] = 0
			j = j + 1
	print(ans)


for p in range(int(input())):
	n = int(input())
	arr = input().split(' ')
	arr = map(int, arr)
	arr = list(arr)
	sumarr = []
	su = 0
	M = max(arr)
	m = min(arr)
	for i in range(len(arr)):
		su += arr[i]
		sumarr.append(su)
	s = set()
	if len(sumarr) >= 2:
		s.add(sumarr[1])
	for i in range(1, len(sumarr)):
		for j in range(i - 1):
			s.add(sumarr[i])
			ans = sumarr[i] - sumarr[j]
			if ans <= M and ans >= m:
				s.add(ans)
	ans = 0
	for d in arr:
		if d in s:
			ans += 1
	print(ans)


import math, sys
from sys import stdin, stdout
from collections import Counter, defaultdict, deque
input = stdin.readline
I = lambda : int(input())
li = lambda : list(map(int, input().split()))

def case():
	n = I()
	a = li()
	d = {}
	m = max(a)
	for i in range(n + 1):
		d[i] = 0
	for i in range(n - 1):
		c = a[i]
		for j in range(i + 1, n):
			if c + a[j] <= m:
				c += a[j]
				d[c] += 1
			else:
				break
	ans = 0
	for i in a:
		if d[i] > 0:
			ans += 1
	print(ans)
for _ in range(int(input())):
	case()


t = int(input())
for z in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = [0] * 2 * n
	count = 0
	if len(set(arr)) == 1:
		print('0')
	else:
		for i in range(n - 1):
			x = arr[i]
			for j in range(i + 1, n):
				x += arr[j]
				if x > n:
					break
				ans[x] = 1
		for i in range(n):
			if ans[arr[i]] == 1:
				count += 1
		print(count)


for t in range(int(input())):
	N = int(input())
	arr = list(map(int, input().split()))
	freq = {}
	for i in range(N):
		if arr[i] in freq:
			freq[arr[i]] += 1
		else:
			freq[arr[i]] = 1
	ans = 0
	for l in range(N):
		s = 0
		for r in range(l, N):
			s += arr[r]
			if l == r:
				continue
			if s <= N and s in freq:
				ans += freq[s]
				freq[s] = 0
	print(ans)


t = int(input())
for i in range(0, t):
	n = int(input())
	a = input().strip().split()
	arr = [int(x) for x in a]
	specials = [0] * (n + 1)
	cum_sum = [0] * (n + 1)
	for i in range(n):
		cum_sum[i + 1] = cum_sum[i] + arr[i]
	for i in range(n + 1):
		for j in range(i + 2, n + 1):
			if cum_sum[j] - cum_sum[i] <= n:
				specials[cum_sum[j] - cum_sum[i]] = 1
	count = 0
	for i in range(n):
		if specials[arr[i]] == 1:
			count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = [0] * (n + 1)
	c = 0
	for i in range(n):
		l1[l[i]] += 1
	for i in range(n):
		s = l[i]
		for j in range(i + 1, n):
			s += l[j]
			if s > n:
				break
			if l1[s] > 0:
				c += l1[s]
				l1[s] = 0
	print(c)


T = int(input())
for m in range(T):
	n = int(input())
	dic = {}
	for i in range(n + 1):
		dic[i] = 0
	l = list(map(int, input().split()))
	for i in l:
		dic[i] = dic[i] + 1
	count = 0
	for d in range(n):
		sum = 0
		for r in range(d, n):
			sum = sum + l[r]
			if r == d:
				continue
			if sum <= n:
				count = count + dic[sum]
				dic[sum] = 0
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * (n + 1)
	i = 0
	for i in range(n):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s <= n:
				b[s] = 1
			else:
				break
	print(sum([b[x] for x in a]))


from sys import stdin, stderr

def rl():
	return [int(w) for w in stdin.readline().split()]
(t,) = rl()
for _ in range(t):
	(n,) = rl()
	a = rl()
	good = [False for i in range(n + 1)]
	s = [0 for i in range(n + 1)]
	for i in range(n):
		s[i + 1] = s[i] + a[i]
		for j in range(i):
			if s[i + 1] - s[j] <= n:
				good[s[i + 1] - s[j]] = True
	r = 0
	for i in range(n):
		if good[a[i]]:
			r += 1
	print(r)


tc = int(input())
while tc != 0:
	tc = tc - 1
	n = int(input())
	a = list(map(int, input().split(' ')))
	c = 0
	b = []
	m = {}
	mx = 0
	for i in range(len(a)):
		c = c + a[i]
		b.append(c)
		mx = max(mx, a[i])
		if a[i] in m:
			m[a[i]] = m[a[i]] + 1
		else:
			m[a[i]] = 1
	c = 0
	for i in range(len(a)):
		s = 0
		for j in range(i, len(a)):
			s = s + a[j]
			if s > mx:
				break
			if s in m and i != j:
				if m[s] != 0:
					c = c + m[s]
				m[s] = 0
	print(c)


for t in range(int(input())):
	n = int(input())
	arr = [int(i) for i in input().split()]
	s = [0] * (n + 1)
	f = [0] * (n + 1)
	for i in range(n - 1):
		c = arr[i]
		for j in range(i + 1, n):
			c += arr[j]
			if c > n:
				break
			s[c] = 1
	for i in range(n):
		f[arr[i]] += 1
	print(sum((s[i] * f[i] for i in range(1, n + 1))))


from sys import stdin, gettrace
from bisect import bisect_left

def input():
	return stdin.buffer.readline()

def main():

	def solve():
		n = int(input())
		aa = [int(a) for a in input().split()]
		ca = [0] * (n + 1)
		for a in aa:
			ca[a] += 1
		count = 0
		for i in range(1, n):
			sm = aa[i]
			for j in range(i - 1, -1, -1):
				sm += aa[j]
				if sm > n:
					break
				count += ca[sm]
				ca[sm] = 0
		print(count)
	q = int(input())
	for _ in range(q):
		solve()
main()


for T in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	used = [0] * (n + 1)
	for i in range(1, n):
		a[i] += a[i - 1]
		if a[i] <= n:
			used[a[i]] = 1
	for i in range(n):
		for j in range(i - 2, -1, -1):
			if a[i] - a[j] > n:
				break
			used[a[i] - a[j]] = True
	res = used[a[0]]
	for i in range(1, n):
		res += used[a[i] - a[i - 1]]
	print(res)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for i in a:
		if i not in d:
			d[i] = [1, 0]
		else:
			d[i][0] += 1
	c = 0
	for i in range(n - 1):
		x = a[i]
		for j in range(i + 1, n):
			x += a[j]
			if x in d:
				if d[x][1] == 0:
					c += d[x][0]
					d[x][1] = 1
	print(c)


def solve(n, s):
	ans = 0
	sums = [0] * (n + 1)
	for i in s:
		sums[i] += 1
	for i in range(n - 1):
		su = s[i]
		for j in range(i + 1, n):
			su += s[j]
			if su > n:
				break
			else:
				ans += sums[su]
				sums[su] = 0
	return ans
t = int(input())
for i in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	print(solve(n, s))


from sys import stdout, stdin
(_input, _print) = (stdin.buffer.readline, stdout.write)
(_sum, _range, _int) = (sum, range, int)

def solution():
	for _ in _range(_int(_input())):
		n = _int(_input())
		arr = [_int(i) for i in _input().split()]
		_sum = [0] * (n + 1)
		c = [0] * 8001
		for i in arr:
			c[i] += 1
		for i in _range(1, n + 1):
			_sum[i] = _sum[i - 1] + arr[i - 1]
		counter = [0]
		for i in _range(n):
			for j in _range(i + 2, n + 1):
				if _sum[j] - _sum[i] <= 8000:
					counter[0] += c[_sum[j] - _sum[i]]
					c[_sum[j] - _sum[i]] = 0
		print(counter[0])
solution()


t = int(input())
import math

def solve(arr):
	shit = {}
	for (i, n) in enumerate(arr):
		try:
			shit[n] += 1
		except:
			shit[n] = 1
	nice = 0
	for i in range(len(arr)):
		r = 0
		for j in range(0, len(arr) - i):
			r += arr[i + j]
			if j > 0:
				if r in shit:
					nice += shit[r]
					shit[r] = 0
	return nice
for _ in range(t):
	n = int(input())
	print(solve([int(x) for x in input().strip().split()]))


numcases = int(input())
for _ in range(numcases):
	n = int(input())
	arr = list(map(int, input().split()))
	pre = []
	curr = 0
	ans = {}
	for i in arr:
		if i not in ans:
			ans[i] = 1
		else:
			ans[i] += 1
	total = 0
	for j in range(n):
		curr = curr + arr[j]
		pre.append(curr)
	for i in range(1, n):
		curr = pre[i]
		if ans.get(curr, 0) != 0:
			total = total + ans.get(curr, 0)
			del ans[curr]
	for i in range(2, n):
		for j in range(i - 1):
			curr = pre[i] - pre[j]
			if ans.get(curr, 0) != 0:
				total = total + ans.get(curr, 0)
				del ans[curr]
	print(total)


from collections import Counter
for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	demo = [0] * (n + 1)
	for j in l:
		demo[j] += 1
	maxi = max(l)
	count = 0
	for x in range(n - 1):
		s = l[x]
		if s == maxi:
			continue
		for y in range(x + 1, n):
			s += l[y]
			if s <= maxi:
				count += demo[s]
				demo[s] = 0
			else:
				break
	print(count)


def getSpecialElements(n, a):
	max_element = max(a)
	table = {}
	for i in a:
		table[i] = table[i] + 1 if i in table else 1
	special = 0
	for i in range(n - 1):
		value = a[i]
		for j in range(i + 1, n):
			value += a[j]
			if value > max_element:
				break
			if value in table:
				special += table[value]
				table.pop(value)
	return special
t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	print(getSpecialElements(n, a))


t = int(input())
while t:
	n = int(input())
	ans = 0
	arr = [int(x) for x in input().split()]
	occ = [0 for i in range(n + 1)]
	for x in arr:
		occ[x] += 1
	for i in range(1, n):
		arr[i] += arr[i - 1]
		if arr[i] <= n:
			ans += occ[arr[i]]
			occ[arr[i]] = 0
	for i in range(2, n):
		for j in range(i - 1):
			if arr[i] - arr[j] <= n:
				ans += occ[arr[i] - arr[j]]
				occ[arr[i] - arr[j]] = 0
	print(ans)
	t -= 1


t = int(input())
while t > 0:
	t = t - 1
	n = int(input())
	a = list(map(int, input().split()))
	b = a.copy()
	b.sort()
	pointer = []
	total = []
	for i in range(1, n):
		pointer.append(i - 1)
		total.append(a[i] + a[i - 1])
	ans = 0
	for i in range(n):
		flag = 0
		for j in range(n - 1):
			while pointer[j] > 0 and total[j] < b[i]:
				pointer[j] = pointer[j] - 1
				total[j] = total[j] + a[pointer[j]]
			if total[j] == b[i]:
				flag = 1
		ans = ans + flag
	print(ans)


import bisect
t = int(input())
for test in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	(sum_arr, sum_d) = ([], {})
	s = 0
	for i in range(n):
		s += arr[i]
		sum_d[s] = i
		sum_arr.append(s)
	ans = 0
	(covered, ans_set) = (set(), set())
	for i in range(n):
		if arr[i] in covered:
			if arr[i] in ans_set:
				ans += 1
			continue
		covered.add(arr[i])
		(num, found) = (arr[i], 0)
		for j in range(0, i):
			if sum_arr[j] == num and j > 0:
				ans += 1
				found = 1
				ans_set.add(arr[i])
				break
			if sum_arr[j] + num in sum_d:
				r = sum_d[sum_arr[j] + num]
				if r < i and r > j + 1:
					ans += 1
					ans_set.add(arr[i])
					found = 1
					break
		if found == 1:
			continue
		for j in range(i, n):
			if sum_arr[j] + num in sum_d:
				r = sum_d[sum_arr[j] + num]
				if r > j + 1:
					ans += 1
					ans_set.add(arr[i])
					found = 1
					break
	print(ans)


import io
import os
from collections import Counter, defaultdict, deque

def solve(N, A):
	pref = [0]
	for x in A:
		pref.append(pref[-1] + x)
	seen = [False] * (N + 1)
	for i in range(N):
		for j in range(i + 2, N + 1):
			x = pref[j] - pref[i]
			if 0 <= x <= N:
				seen[pref[j] - pref[i]] = True
	return sum((1 for x in A if seen[x]))
T = int(input())
for t in range(T):
	(N,) = [int(x) for x in input().split()]
	A = [int(x) for x in input().split()]
	ans = solve(N, A)
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	d = dict()
	for i in a:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	ans = 0
	for i in range(n):
		sum = a[i]
		for j in range(i + 1, n):
			sum += a[j]
			if sum in d:
				ans += d[sum]
				d[sum] = 0
	print(ans)


for _ in range(int(input())):
	n = int(input())
	L = list(map(int, input().split()))
	ans = 0
	count = [0] * (n + 1)
	for i in range(n):
		total = L[i]
		for j in range(i + 1, n):
			total += L[j]
			if total <= n and total > 0:
				count[total] += 1
	for k in range(n):
		if count[L[k]] > 0:
			ans += 1
	print(ans)


t = int(input())
spl = []
for i in range(8001):
	spl.append(0)
for i in range(t):
	n = int(input())
	arr = input().split(' ')
	for j in range(n):
		arr[j] = int(arr[j])
	for j in range(n):
		curr = arr[j]
		for k in range(j + 1, n):
			curr += arr[k]
			if curr > 8000:
				break
			spl[curr] = 1
	ans = 0
	for j in range(n):
		ans += spl[arr[j]]
	for j in range(8001):
		spl[j] = 0
	print(ans)


from collections import defaultdict, Counter

def solve2(arr, n):
	hmap = defaultdict(int)
	ans = 0
	for i in range(n):
		curr_sum = arr[i]
		for j in range(i + 1, n):
			curr_sum += arr[j]
			if 0 < curr_sum <= n:
				hmap[curr_sum] += 1
	ctr = Counter(arr)
	for (k, v) in hmap.items():
		if k in arr:
			ans += ctr[k]
	print(ans)

def solve(arr, n):
	c = [0] * (n + 1)
	ans = 0
	for i in range(n):
		s = arr[i]
		for j in range(i + 1, n):
			s += arr[j]
			if 0 < s <= n:
				c[s] += 1
	for i in range(n):
		ans += c[arr[i]] > 0
	print(ans)
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	solve(arr, n)


t = int(input())
for _ in range(t):
	from collections import Counter
	n = int(input())
	arr = [int(i) for i in input().split()]
	cnt = Counter(arr)
	keys = list(cnt.keys())
	c1 = [0] * (n + 1)
	for i in keys:
		c1[i] = 1
	ans = 0
	for i in range(n - 1):
		temp = arr[i]
		for j in range(i + 1, n):
			temp += arr[j]
			if temp > n:
				break
			if c1[temp] == 1:
				ans += cnt[temp]
				c1[temp] = 0
	print(ans)


from collections import Counter
t = int(input())
cnt = 0
while cnt < t:
	cnt += 1
	n = int(input())
	a = [int(i) for i in input().split()]
	d = Counter(a)
	set1 = set(a)
	set2 = set()
	b = [0] * n
	b[0] = a[0]
	for i in range(1, n):
		b[i] = b[i - 1] + a[i]
	for j in range(1, n):
		if b[j] <= n:
			set2.add(b[j])
		else:
			break
	for i in range(1, n):
		for j in range(i + 1, n):
			if b[j] - b[i - 1] <= n:
				set2.add(b[j] - b[i - 1])
			else:
				break
	res = 0
	for elem in set1 & set2:
		res += d[elem]
	print(res)


from sys import stdin, stdout
for _ in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	visit = [0 for i in range(n + 1)]
	for i in range(n - 1):
		(k, p) = (a[i], 0)
		for j in range(i + 1, n):
			p += a[j]
			if p + k > n:
				break
			else:
				visit[p + k] = 1
	k = 0
	for i in a:
		if visit[i] == 1:
			k += 1
	stdout.write(str(k) + '\n')


tc = int(input())
for _ in range(tc):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	freq = {}
	for num in arr:
		if num in freq:
			freq[num] += 1
		else:
			freq[num] = 1
	ans = y = x = 0
	lenn = len(arr)
	for i in range(lenn):
		x += arr[i]
		y = 0
		if i >= 1 and x in freq:
			ans += freq[x]
			freq.pop(x)
		for j in range(0, i - 1):
			y += arr[j]
			if x - y in freq:
				ans += freq[x - y]
				freq.pop(x - y)
	print(ans)


from math import *
from sys import *
t = int(stdin.readline().strip())
for _ in range(t):
	n = int(stdin.readline().strip())
	a = list(map(int, stdin.readline().strip().split()))
	k = max(a)
	b = [0] * (k + 1)
	l = set()
	for i in range(n):
		s = a[i]
		for j in range(i + 1, n):
			s = s + a[j]
			if s <= k:
				l.add(s)
			else:
				break
	l = list(l)
	c = 0
	for i in a:
		b[i] = b[i] + 1
	for i in l:
		c = c + b[i]
	print(c)


for TT in range(int(input())):
	m = {}
	n = int(input())
	l = list(map(int, input().split()))
	for i in l:
		if i in m:
			m[i] += 1
		else:
			m[i] = 1
	s = 0
	for i in range(n):
		t = 0
		p = l[i]
		for j in range(i + 1, n):
			t += l[j]
			if p + t > n:
				break
			if p + t in m:
				s += m[p + t]
				m[p + t] = 0
	print(s)


T = int(input())
for _ in range(T):
	n = int(input())
	ar = list(map(int, input().split()))
	c = 0
	m = [0] * (n + 1)
	for i in range(n):
		s = ar[i]
		for j in range(i + 1, n):
			s += ar[j]
			if s <= n:
				m[s] = 1
			else:
				break
	for k in ar:
		if m[k] > 0:
			c += 1
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	occurence_arr = {}
	for j in range(n):
		if arr[j] not in occurence_arr:
			occurence_arr[arr[j]] = 1
		else:
			occurence_arr[arr[j]] += 1
	count = 0
	for l in range(n):
		total = 0
		for r in range(l, n):
			total += arr[r]
			if l == r:
				continue
			if total <= n:
				if total in occurence_arr:
					count += occurence_arr[total]
					occurence_arr[total] = 0
	print(count)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = [0] * n
	ans = 0
	for i in range(len(a)):
		cnt[a[i] - 1] += 1
	for i in range(len(a)):
		cursum = 0
		for j in range(i, n):
			cursum += a[j]
			if i == j:
				continue
			if cursum <= n:
				ans += cnt[cursum - 1]
				cnt[cursum - 1] = 0
			else:
				break
	print(ans)


from collections import deque
from collections import OrderedDict
import math
import sys
import os
from io import BytesIO
import threading
import bisect
input = sys.stdin.readline
limit = 8002
for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	special = [False] * limit
	for i in range(n):
		s = arr[i]
		for j in range(i + 1, n):
			s += arr[j]
			if s >= limit:
				break
			special[s] = True
	print(sum((1 for x in arr if special[x])))


for _ in range(int(input())):
	n = int(input())
	lst = list(map(int, input().split()))
	arr = [0] * (n + 1)
	c = 0
	for i in lst:
		arr[i] += 1
	for i in range(n):
		s = lst[i]
		for j in range(i + 1, n):
			s += lst[j]
			if s <= n:
				c += arr[s]
				arr[s] = 0
			else:
				break
	print(c)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
testcases = int(input())
for j in range(testcases):
	n = int(input())
	count = 0
	input1 = input().split()
	prefsum = []
	maxsofar = 0
	for s in range(n):
		count += int(input1[s])
		if int(input1[s]) > maxsofar:
			maxsofar = int(input1[s])
		prefsum.append(count)
	setty = set(prefsum[1:])
	for s in range(n):
		for k in range(s + 2, n):
			if prefsum[k] - prefsum[s] <= maxsofar:
				setty.add(prefsum[k] - prefsum[s])
	num = 0
	for s in range(n):
		if s == 0:
			if prefsum[s] in setty:
				num += 1
		elif prefsum[s] - prefsum[s - 1] in setty:
			num += 1
	print(num)


for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	freq = [0] * (n + 1)
	for a in A:
		freq[a] += 1
	res = 0
	for l in range(n):
		sm = A[l]
		for r in range(l + 1, n):
			sm += A[r]
			if sm <= n:
				res += freq[sm]
				freq[sm] = 0
	print(res)


from collections import Counter
import sys
input = sys.stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = Counter(a)
	pref = [0] * n
	pref[0] = a[0]
	for i in range(1, n):
		pref[i] = pref[i - 1] + a[i]
	ans = 0
	pref = [0] + pref
	for i in range(1, n + 1):
		for j in range(i + 1, n + 1):
			if d[pref[j] - pref[i - 1]] > 0 and 1 <= pref[j] - pref[i - 1] <= n:
				ans += d[pref[j] - pref[i - 1]]
				d[pref[j] - pref[i - 1]] = 0
	print(ans)


from collections import defaultdict
from queue import LifoQueue

def print_sol(c, sol):
	print('Case #{}: {}'.format(c, sol))

def rd_int():
	return int(input())

def rd_str():
	return input()

def rd_str_lst():
	return input().split(' ')

def sp_str_lst():
	return list(input())

def rd_int_lst():
	return [int(i) for i in rd_str_lst()]

def sp_int_lst():
	return [int(i) for i in sp_str_lst()]

def dfs(g, i, v):
	v[i] = True
	for j in g[i]:
		if not v[j]:
			dfs(g, j, v)
	print(i)

def dfs_iter(g, i, n):
	v = [False] * n
	stack = LifoQueue()
	stack.put(i)
	while stack.not_empty:
		u = stack.get()
		v[u] = True
		print(u)
		for i in g[u]:
			if not v[i]:
				stack.put(i)

def als(x):
	sa = [1 if i % 2 == 0 else 0 for i in range(x)]
	return sa

def main():
	t = rd_int()
	for c in range(1, t + 1):
		n = rd_int()
		a = rd_int_lst()
		cnt = defaultdict(lambda : 0)
		for i in a:
			cnt[i] += 1
		sol = 0
		for i in range(2, n):
			s = sum(a[0:i])
			if s <= n:
				sol += cnt[s]
				cnt[s] = 0
			for j in range(i, n):
				s += a[j] - a[j - i]
				if s <= n:
					sol += cnt[s]
					cnt[s] = 0
		print(sol)
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = [0] * (n + 1)
	for x in a:
		cnt[x] += 1
	ans = 0
	for l in range(n):
		s = 0
		for r in range(l, n):
			s += a[r]
			if l == r or s > n:
				continue
			ans += cnt[s]
			cnt[s] = 0
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(el) for el in input().split()]
	dp = [[0, 0] for i in range(n + 1)]
	for i in range(n):
		dp[arr[i]][0] += 1
	ans = 0
	for i in range(n):
		sm = arr[i]
		for j in range(i + 1, n):
			sm += arr[j]
			if sm <= n:
				if dp[sm][1] == 0:
					ans += dp[sm][0]
					dp[sm][1] = 1
			else:
				break
	print(ans)


t = int(input())
for w in range(t):
	n = int(input())
	l = [int(i) for i in input().split()]
	l1 = [0] * 8001
	for i in range(n):
		k = l[i]
		for j in range(i + 1, n):
			k += l[j]
			if k <= n:
				l1[k] += 1
	c = 0
	for i in range(n):
		if l1[l[i]] != 0:
			c += 1
	print(c)


import collections

def solution1(a):
	cnt = 0
	max_ = max(a)
	c = collections.Counter(a)
	cur_sum = 0
	for right_border in range(len(a) - 1):
		cur_sum = a[right_border]
		for left_border in range(right_border + 1, len(a)):
			cur_sum += a[left_border]
			if c[cur_sum] != 0:
				cnt += c[cur_sum]
				c[cur_sum] = 0
			if cur_sum > max_:
				break
	print(cnt)
inp = int(input())
for _ in range(inp):
	_ = input()
	input_ = tuple(map(int, input().split()))
	solution1(input_)


for _ in range(int(input())):
	n = int(input())
	a = []
	cnt = [0] * (n + 1)
	for ele in map(int, input().split()):
		cnt[ele] += 1
		a.append(ele)
	ans = 0
	for l in range(n):
		sum = 0
		for r in range(l, n):
			sum += a[r]
			if l == r:
				continue
			if sum <= n:
				ans += cnt[sum]
				cnt[sum] = 0
			else:
				break
	print(ans)


class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from bisect import bisect_right, bisect_left
from fractions import Fraction

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def pari(a):
	for i in range(0, 2, n):
		print(i)
	for i in range(1, 2, n):
		print(i)
from math import gcd

def lcm(a, b):
	return a * b // gcd(a, b)

def f(n, a=1):
	if a == 1:
		a = []
	s = len(str(n))
	p = 10 ** (s - 1)
	ans = 1
	a += [n // p * p]
	n -= a[0]
	if n:
		ans += 1
		a += f(n)
		return a
	else:
		return a
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(0)
		continue
	mx = max(a)
	st = set()
	for i in range(n - 1):
		start = a[i] + a[i + 1]
		st.add(start)
		for j in range(i + 2, n):
			start += a[j]
			if start > mx:
				break
			st.add(start)
	ans = 0
	for each in a:
		if each in st:
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	qq = 0
	n = int(input())
	s = str(input())
	if len(s) > 1:
		a = list(map(int, s.split()))
	else:
		a = [int(s)]
	q = [0] * len(a)
	for i in a:
		q[i - 1] += 1
	for i in range(n):
		summa = 0
		for j in range(i, n):
			summa += a[j]
			if i == j:
				continue
			if summa <= n:
				qq += q[summa - 1]
				q[summa - 1] = 0
	print(qq)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	dic = {}
	for i in range(n - 1):
		s = arr[i]
		for j in range(i + 1, n):
			s += arr[j]
			if s > n:
				break
			else:
				dic[s] = 1
	ans = 0
	for i in arr:
		try:
			if dic[i]:
				ans += 1
		except:
			continue
	print(ans)


def test_case():
	n = int(input())
	a = [int(x) for x in input().split()]
	c = [0] * (n + 1)
	for x in a:
		c[x] += 1
	ans = 0
	for i in range(n - 1):
		total = a[i]
		for j in range(i + 1, n):
			total += a[j]
			if total > n:
				break
			ans += c[total]
			c[total] = 0
	print(ans)
T = int(input())
for _ in range(T):
	test_case()


from itertools import islice

def solve(a):
	N = len(a)
	d = [0] * (N + 1)
	for i in range(N - 1):
		cur = a[i]
		for j in range(i + 1, N):
			cur += a[j]
			if cur > N:
				break
			d[cur] = 1
	print(sum((d[x] for x in a)))
for s in islice(open(0), 2, None, 2):
	a = (*map(int, s.split()),)
	solve(a)


for lol in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	d = {}
	c = 0
	for i in l:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	ans = 0
	for i in range(n - 1):
		c = l[i]
		for j in range(i + 1, n):
			c += l[j]
			if c in d:
				ans += d[c]
				del d[c]
	print(ans)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	for i in range(len(a)):
		if d.get(a[i]) == None:
			d[a[i]] = 1
		else:
			d[a[i]] += 1
	for i in range(1, len(a)):
		a[i] += a[i - 1]
	cnt = 0
	for i in range(1, len(a)):
		temp = a[i]
		if temp in d:
			cnt += d[temp]
			d[temp] = 0
		for j in range(i + 1, len(a)):
			if a[j] - a[j - (i + 1)] in d:
				cnt += d[a[j] - a[j - (i + 1)]]
				d[a[j] - a[j - (i + 1)]] = 0
	print(cnt)
t = int(input())
while t:
	main()
	t -= 1


x = int(input())
for i in range(x):
	n = int(input())
	l = list(map(int, input().split()))
	a = [0] * (n + 1)
	max = 0
	for i in l:
		a[i] += 1
		if i > max:
			max = i
	count = 0
	for i in range(0, n - 1):
		s = 0
		for j in range(i, n):
			s += l[j]
			if i != j:
				if s > max:
					break
				if s <= max and a[s] != 0:
					count += a[s]
					a[s] = 0
	print(count)


t = int(input())
while t > 0:
	n = int(input())
	a = [int(ele) for ele in input().split()]
	mem = {}
	for i in range(n):
		if a[i] in mem.keys():
			mem[a[i]] += 1
		else:
			mem[a[i]] = 1
	count = 0
	for i in range(n):
		sumi = a[i]
		for j in range(i + 1, n):
			sumi += a[j]
			if sumi in mem.keys():
				count += mem[sumi]
				del mem[sumi]
	print(count)
	t -= 1


from collections import defaultdict
t = int(input())
for tt in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	maxi = max(a)
	D = defaultdict(lambda : False)
	for l in range(n):
		som = a[l]
		for r in range(l + 1, n):
			som += a[r]
			if som > maxi:
				break
			D[som] = True
	count = 0
	for elt in a:
		if D[elt]:
			count += 1
	print(count)


def main():
	caseNum = int(input())
	for _ in range(caseNum):
		(length, array) = [int(input()), list(map(int, input().split(' ')))]
		print(findSpElem(array, length))

def findSpElem(array: list, length: int):
	SpElemNum = 0
	valueNum = [0 for _ in range(length + 1)]
	for elem in array:
		valueNum[elem] += 1
	for i in range(length - 1):
		Sum = array[i]
		for j in range(i + 1, length):
			Sum += array[j]
			if Sum > length:
				break
			if valueNum[Sum] > 0:
				SpElemNum += valueNum[Sum]
				valueNum[Sum] = 0
	return SpElemNum
main()


count = int(input())
for i in range(count):
	number = int(input())
	numbers = input().split(' ')
	maximum = 0
	numbers_int = [0] * number
	count_num = [0] * number
	number_is_special = [0] * number
	for j in range(number):
		numbers_int[j] = int(numbers[j])
		if numbers_int[j] > maximum:
			maximum = numbers_int[j]
		count_num[int(numbers[j]) - 1] += 1
	if number > 2:
		counter = 0
		step = 1
		addition = numbers_int[counter]
		while counter < number - 1:
			addition += numbers_int[counter + step]
			if addition <= maximum:
				number_is_special[addition - 1] = 1
				if counter + step < number - 1:
					step += 1
				else:
					counter += 1
					step = 1
					addition = numbers_int[counter]
			else:
				counter += 1
				step = 1
				addition = numbers_int[counter]
	result = 0
	for j in range(number):
		result += number_is_special[j] * count_num[j]
	print(result)


for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	used = [0] * 8001
	for i in range(n):
		sm = a[i]
		for j in range(i + 1, n):
			sm += a[j]
			if sm <= 8000:
				used[sm] = 1
	sm = 0
	for i in range(n):
		if used[a[i]] == 1:
			sm += 1
	print(sm)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	visited = []
	for i in range(n):
		l = 0
		r = 1
		if n >= 2:
			sum = arr[0] + arr[1]
		while l < n - 1 and r < n:
			if sum == arr[i] and i not in visited:
				visited.append(i)
				ans += 1
				break
			elif sum > arr[i]:
				if r == l + 1:
					l += 1
					r += 1
					sum = arr[l] + arr[min(r, n - 1)]
				else:
					sum -= arr[l]
					l += 1
			else:
				r += 1
				sum += arr[min(r, n - 1)]
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	s = [0] * (n + 1)
	for (i, ai) in enumerate(a):
		cnt = a[i]
		for j in range(i + 1, n):
			cnt += a[j]
			if cnt > n:
				break
			s[cnt] = 1
	print(sum((s[ai] for ai in a)))


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	check = [0] * (n + 1)
	count = 0
	for i in range(n - 1):
		s = arr[i]
		for j in range(i + 1, n):
			s = s + arr[j]
			if s <= n:
				check[s] = 1
	for i in arr:
		if check[i] == 1:
			count += 1
	print(count)


t = int(input())
answers = []
for _ in range(t):
	n = int(input())
	arr = [int(i) for i in input().split()]
	possible = [False for i in range(n + 1)]
	diff_array = [0]
	for i in range(n):
		diff_array.append(diff_array[-1] + arr[i])
	for i in range(n):
		for j in range(i + 1, n):
			s = diff_array[j + 1] - diff_array[i]
			if s > n:
				continue
			else:
				possible[s] = True
	ans = 0
	for i in arr:
		if possible[i]:
			ans += 1
	answers.append(ans)
print(*answers, sep='\n')


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	cnts = [0] * (n + 1)
	for e in a:
		cnts[e] += 1
	specials = [0] * (n + 1)
	pref = [0]
	for e in a:
		pref.append(pref[-1] + e)
	for i in range(1, n):
		for j in range(i + 1, n + 1):
			sm = pref[j] - pref[i - 1]
			if sm <= n:
				specials[sm] = 1
	ans = 0
	for i in range(len(specials)):
		ans += specials[i] * cnts[i]
	print(ans)


for t in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	count = 0
	d = {}
	for i in l:
		if i in d:
			d[i] += 1
		else:
			d[i] = 1
	for i in range(n):
		s = l[i]
		for j in range(i + 1, n):
			s += l[j]
			if s in d:
				count += d[s]
				del d[s]
	print(count)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
import sys
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	el_count = {}
	prefix_sum = [0 for i in range(n + 1)]
	for i in range(n):
		prefix_sum[i + 1] = prefix_sum[i] + a[i]
		el_count[a[i]] = el_count.get(a[i], 0) + 1
	ans = 0
	for start in range(n):
		for sec in range(start + 1, n):
			sum_ = prefix_sum[sec + 1] - prefix_sum[start]
			if sum_ in el_count:
				ans += el_count.get(sum_, 0)
				el_count[sum_] = 0
	sys.stdout.write(str(ans) + '\n')


for tc in range(int(input())):
	n = int(input())
	arr = [int(x) for x in input().split()]
	counts = [0 for i in range(n + 1)]
	for val in arr:
		counts[val] += 1
	count = 0
	for l in range(n - 1):
		curr = arr[l]
		for r in range(l + 1, n):
			curr += arr[r]
			if curr > n:
				break
			if counts[curr]:
				count += counts[curr]
				counts[curr] = 0
	print(count)


from __future__ import division, print_function
import math
import os
import sys
from fractions import *
from sys import *
from decimal import *
from io import BytesIO, IOBase
from itertools import accumulate, combinations, permutations, combinations_with_replacement, product
from collections import *
import timeit, time
M = 10 ** 9 + 7
import heapq
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def fsep():
	return map(float, inp().split())

def inpu():
	return int(inp())

def regularbracket(t):
	p = 0
	for i in t:
		if i == '(':
			p += 1
		else:
			p -= 1
		if p < 0:
			return False
	else:
		if p > 0:
			return False
		else:
			return True

def binarySearchcount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] <= key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def binarySearch(arr, n, key):
	left = 0
	right = n - 1
	while left <= right:
		mid = (right + left) // 2
		if arr[mid] == key:
			return mid
		if arr[mid] <= key:
			left = mid + 1
		else:
			right = mid - 1
	return -1

def ternarysearch(arr, n, key):
	(l, r) = (0, n - 1)
	while l <= r:
		mid = (-l + r) // 3 + l
		mid2 = mid + (-l + r) // 3
		if arr[mid] == key:
			return mid
		if arr[mid2] == key:
			return mid2
		if arr[mid] > key:
			r = mid - 1
		elif arr[mid2] < key:
			l = mid2 + 1
		else:
			l = mid + 1
			r = mid2 - 1
	return -1

def reverse1(string):
	pp = ''
	for i in string[::-1]:
		pp += i
	if pp == string:
		return True
	return False

def reverse2(list1):
	l = []
	for i in list1[::-1]:
		l.append(i)
	if l == list1:
		return True
	return False

def mex(list1):
	p = max(list1) + 1
	for i in range(len(list1)):
		if list1[i] != i:
			p = i
			break
	return p

def sumofdigits(n):
	n = str(n)
	s1 = 0
	for i in n:
		s1 += int(i)
	return s1

def perfect_square(n):
	s = math.sqrt(n)
	if s == int(s):
		return True
	return False

def prime(x):
	if x == 1:
		return False
	else:
		for i in range(2, int(math.sqrt(x)) + 1):
			if x % i == 0:
				return False
		else:
			return True

def roman_number(x):
	if x > 15999:
		return
	value = [5000, 4000, 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]
	symbol = ['F', 'MF', 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I']
	roman = ''
	i = 0
	while x > 0:
		div = x // value[i]
		x = x % value[i]
		while div:
			roman += symbol[i]
			div -= 1
		i += 1
	return roman

def soretd(s):
	for i in range(1, len(s)):
		if s[i - 1] > s[i]:
			return False
	return True

def countRhombi(h, w):
	ct = 0
	for i in range(2, h + 1, 2):
		for j in range(2, w + 1, 2):
			ct += (h - i + 1) * (w - j + 1)
	return ct

def countrhombi2(h, w):
	return h * h // 4 * (w * w // 4)

def binpow(a, b):
	if b == 0:
		return 1
	else:
		res = binpow(a, b // 2)
	if b % 2 != 0:
		return res * res * a
	else:
		return res * res

def binpowmodulus(a, b, m):
	a %= m
	res = 1
	while b > 0:
		if b & 1:
			res = res * a % m
		a = a * a % m
		b >>= 1
	return res

def coprime_to_n(n):
	result = n
	i = 2
	while i * i <= n:
		if n % i == 0:
			while n % i == 0:
				n //= i
			result -= result // i
		i += 1
	if n > 1:
		result -= result // n
	return result

def luckynumwithequalnumberoffourandseven(x, n, a):
	if x >= n and str(x).count('4') == str(x).count('7'):
		a.append(x)
	elif x < 1000000000000.0:
		luckynumwithequalnumberoffourandseven(x * 10 + 4, n, a)
		luckynumwithequalnumberoffourandseven(x * 10 + 7, n, a)
	return a

def luckynum(x, l, r, a):
	if x >= l and x <= r:
		a.append(x)
	if x > r:
		a.append(x)
		return a
	if x < 10000000000.0:
		luckynum(x * 10 + 4, l, r, a)
		luckynum(x * 10 + 7, l, r, a)
	return a

def luckynuber(x, n, a):
	p = set(str(x))
	if len(p) <= 2:
		a.append(x)
	if x < n:
		luckynuber(x + 1, n, a)
	return a

def interact(type, x):
	if type == 'r':
		inp = input()
		return inp.strip()
	else:
		print(x, flush=True)

def findTrailingZeros(n):
	count = 0
	while n >= 5:
		n //= 5
		count += n
	return count

def mergeSort(arr):
	if len(arr) > 1:
		mid = len(arr) // 2
		L = arr[:mid]
		R = arr[mid:]
		mergeSort(L)
		mergeSort(R)
		i = j = k = 0
		while i < len(L) and j < len(R):
			if L[i] < R[j]:
				arr[k] = L[i]
				i += 1
			else:
				arr[k] = R[j]
				j += 1
			k += 1
		while i < len(L):
			arr[k] = L[i]
			i += 1
			k += 1
		while j < len(R):
			arr[k] = R[j]
			j += 1
			k += 1
res = set()

def solven(p, l, a, b, n):
	if p > n or l > 10:
		return
	if p > 0:
		res.add(p)
	solven(p * 10 + a, l + 1, a, b, n)
	solven(p * 10 + b, l + 1, a, b, n)

def subsetsUtil(A, subset, index, d):
	print(*subset)
	s = sum(subset)
	d.append(s)
	for i in range(index, len(A)):
		subset.append(A[i])
		subsetsUtil(A, subset, i + 1, d)
		subset.pop(-1)
	return d

def subsetSums(arr, l, r, d, sum=0):
	if l > r:
		d.append(sum)
		return
	subsetSums(arr, l + 1, r, d, sum + arr[l])
	subsetSums(arr, l + 1, r, d, sum)
	return d

def print_factors(x):
	factors = []
	for i in range(1, x + 1):
		if x % i == 0:
			factors.append(i)
	return factors

def calc(X, d, ans, D):
	if len(X) == 0:
		return
	i = X.index(max(X))
	ans[D[max(X)]] = d
	Y = X[:i]
	Z = X[i + 1:]
	calc(Y, d + 1, ans, D)
	calc(Z, d + 1, ans, D)

def factorization(n, l):
	c = n
	if prime(n) == True:
		l.append(n)
		return l
	for i in range(2, c):
		if n == 1:
			break
		while n % i == 0:
			l.append(i)
			n = n // i
	return l

def good(b):
	l = []
	i = 0
	while len(b) != 0:
		if b[i] < b[len(b) - 1 - i]:
			l.append(b[i])
			b.remove(b[i])
		else:
			l.append(b[len(b) - 1 - i])
			b.remove(b[len(b) - 1 - i])
	if l == sorted(l):
		return True
	return False

def generate(st, s):
	if len(s) == 0:
		return
	if s not in st:
		st.add(s)
		for i in range(len(s)):
			t = list(s).copy()
			t.remove(s[i])
			t = ''.join(t)
			generate(st, t)
	return

def largestincreasingsubsequence(A):
	l = [1] * len(A)
	sub = []
	for i in range(1, len(l)):
		for k in range(i):
			if A[k] < A[i]:
				sub.append(l[k])
		l[i] = 1 + max(sub, default=0)
	return max(l, default=0)

def findOR(nums, N):
	prefix_sum = 0
	result = 0
	for i in range(N):
		result |= nums[i]
		prefix_sum += nums[i]
		result |= prefix_sum
	return result

def OR(a, n):
	ans = a[0]
	for i in range(1, n):
		ans |= a[i]
	return ans

def toString(List):
	return ''.join(List)

def permute(a, l, r, p):
	if l == r:
		p.append(toString(a))
	else:
		for i in range(l, r + 1):
			(a[l], a[i]) = (a[i], a[l])
			permute(a, l + 1, r, p)
			(a[l], a[i]) = (a[i], a[l])

def squareRoot(number, precision):
	start = 0
	(end, ans) = (number, 1)
	while start <= end:
		mid = int((start + end) / 2)
		if mid * mid == number:
			ans = mid
			break
		if mid * mid < number:
			start = mid + 1
		else:
			end = mid - 1
	increment = 0.1
	for i in range(0, precision):
		while ans * ans <= number:
			ans += increment
		ans = ans - increment
		increment = increment / 10
	return ans

def countRectangles(l, w):
	squareSide = math.gcd(l, w)
	return int(l * w / (squareSide * squareSide))

def count_same_digit(L, R):
	tmp = 0
	ans = 0
	n = int(math.log10(R) + 1)
	for i in range(0, n):
		tmp = tmp * 10 + 1
		for j in range(1, 10):
			if L <= tmp * j and tmp * j <= R:
				ans += 1
	return ans

def findCrossOver(arr, low, high, x):
	if arr[high] <= x:
		return high
	if arr[low] > x:
		return low
	mid = (low + high) // 2
	if arr[mid] <= x and arr[mid + 1] > x:
		return mid
	if arr[mid] < x:
		return findCrossOver(arr, mid + 1, high, x)
	return findCrossOver(arr, low, mid - 1, x)

def Kclosest(arr, x, k, n, ans):
	l = findCrossOver(arr, 0, n - 1, x)
	r = l + 1
	count = 0
	if arr[l] == x:
		l -= 1
	while l >= 0 and r < n and (count < k):
		if x - arr[l] < arr[r] - x:
			ans.append(arr[l])
			l -= 1
		else:
			ans.append(arr[r])
			r += 1
		count += 1
	while count < k and l >= 0:
		ans.append(arr[l])
		l -= 1
		count += 1
	while count < k and r < n:
		ans.append(arr[r])
		r += 1
		count += 1
	return ans

def calcSum(arr, n, k):
	l = []
	sum = 0
	for i in range(k):
		sum += arr[i]
	l.append(sum)
	for i in range(k, n):
		sum = sum - arr[i - k] + arr[i]
		l.append(sum)
	return l

def luckynumber(x, n, a):
	if x > 0:
		a.append(x)
	if x > 10 ** 9:
		return a
	elif x < 1000000000000.0:
		luckynumber(x * 10 + 4, n, a)
		luckynumber(x * 10 + 7, n, a)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def query1(l, r):
	if l >= r:
		return -1
	print('?', l + 1, r + 1)
	sys.stdout.flush()
	return int(input()) - 1

def answer(p):
	print('!', p + 1)
	sys.stdout.flush()
	exit()

def maxSubArraySum(a, size):
	max_so_far = a[0]
	curr_max = a[0]
	for i in range(1, size):
		curr_max = max(a[i], curr_max + a[i])
		max_so_far = max(max_so_far, curr_max)
	return max_so_far

def main():
	for _ in range(int(input())):
		n = inpu()
		arr = lis()
		s = set()
		for i in range(n - 1):
			S = arr[i]
			for i in range(i + 1, n):
				S += arr[i]
				if S > n:
					break
				s.add(S)
		ans = 0
		for i in arr:
			if i in s:
				ans += 1
		print(ans)
main()


def solve(a, n, s):
	sh = 0
	css = a[0]
	jj = 1
	while jj <= n:
		while sh < jj - 1 and css > s:
			css = css - a[sh]
			sh += 1
		if css == s:
			if sh != jj - 1:
				return 1
		if jj < n:
			css = css + a[jj]
		jj += 1
	return 0
t = int(input())
for _ in range(0, t):
	n = int(input())
	a = [int(z) for z in input().split()]
	result = 0
	for i in range(0, n):
		zz = solve(a, n, a[i])
		if zz == 1:
			result += 1
	print(result)


for testcase in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	special = [False] * (n + 1)
	for i in range(n):
		s = arr[i]
		for j in range(i + 1, n):
			s += arr[j]
			if s > n:
				break
			special[s] = True
	print(sum((1 for x in arr if special[x])))


def main():
	n = int(input())
	arr = []
	for _ in range(n):
		temp = input()
		arr.append(list(map(int, input().split())))
	for i in range(n):
		calcSpecialNumber(arr[i])

def calcSpecialNumber(arr):
	count = 0
	lenarr = len(arr)
	keepcount = set()
	for i in range(0, lenarr - 1):
		val = arr[i]
		for j in range(i + 1, lenarr):
			val += arr[j]
			if val > lenarr:
				break
			else:
				keepcount.add(val)
	for i in range(lenarr):
		if arr[i] in keepcount:
			count += 1
	print(count)
main()


import collections

def solve(n, arr):
	isSpecial = [False for _ in range(n + 1)]
	for l in range(n):
		s = arr[l]
		for r in range(l + 1, n):
			s += arr[r]
			if s > n:
				break
			isSpecial[s] = True
	return sum([isSpecial[num] for num in arr])
t = int(input().strip())
for i in range(t):
	n = int(input().strip())
	arr = list(map(int, input().strip().split()))
	print(solve(n, arr))


import sys
import math
import operator as op
from functools import reduce

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom
t = read_int()
for i in range(t):
	n = read_int()
	a = read_int_line()
	d = {}
	d1 = {}
	for i in range(n):
		if a[i] in d:
			d[a[i]] += 1
		else:
			d[a[i]] = 1
	su = [0] * n
	su[0] = a[0]
	for i in range(1, n):
		su[i] = su[i - 1] + a[i]
	ans = 0
	for i in range(n):
		for j in range(i + 1, n):
			if i >= 1:
				val = su[j] - su[i - 1]
			else:
				val = su[j]
			if val > n:
				break
			if val in d1:
				continue
			elif val in d:
				ans += d[val]
				d1[val] = 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	x = [int(i) for i in input().split()]
	d = {}
	ma = 0
	for i in range(n):
		if x[i] not in d:
			d[x[i]] = 0
		d[x[i]] += 1
		ma = max(ma, x[i])
	c = 0
	for i in range(n):
		dp = x[i]
		for j in range(i + 1, n):
			dp = dp + x[j]
			if dp > ma:
				break
			if dp in d and d[dp] != 0:
				c += d[dp]
				d[dp] = 0
	print(c)


from sys import stdin, stdout
from math import gcd, ceil, sqrt
from collections import Counter
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
tc = ii1()
for _ in range(tc):
	n = ii1()
	arr = iia()
	d = Counter(arr)
	res = 0
	for i in range(n):
		cur = arr[i]
		for j in range(i + 1, n):
			cur += arr[j]
			if cur in d:
				res += d[cur]
				del d[cur]
	print(res)


from math import gcd, ceil
from collections import defaultdict as dd

def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))

def ar(element, size):
	return [element for i in range(size)]

def digitsum(num):
	su = 0
	while num:
		su += num % 10
		num //= 10
	return su

def pred(n, k, pointer):
	return pointer - k >= n
for i in range(inin()):
	n = inin()
	arr = inar()
	prefarr = [0]
	prev = 0
	mapp = [False for i in range(n + 7)]
	for i in arr:
		ele = prev + i
		prefarr.append(ele)
		prev = ele
	for l in range(1, n):
		for r in range(l + 1, n + 1):
			op = prefarr[r] - prefarr[l - 1]
			if 0 < op < n + 7:
				mapp[op] = True
	ans = 0
	for i in arr:
		if mapp[i]:
			ans += 1
	print(ans)


def check(arr, num):
	if len(arr) == 1:
		return False
	tmp = 1
	tmpsum = arr[0] + arr[1]
	i = 0
	j = 1
	while i < len(arr) - 1 or j < len(arr):
		if tmpsum == num:
			return True
		if tmpsum > num:
			if i + 1 < j:
				tmpsum -= arr[i]
				i += 1
			else:
				i += 1
				j += 1
				if j == len(arr) or i == len(arr) - 1:
					break
				tmpsum = tmpsum - arr[i - 1] + arr[j]
		elif tmpsum < num:
			j += 1
			if j >= len(arr):
				break
			tmpsum += arr[j]
	return False
for _ in range(int(input())):
	_ = input()
	arr = list(map(int, input().split()))
	print(sum([check(arr, i) for i in arr]))


import sys
input = sys.stdin.buffer.readline
from collections import Counter

def prog():
	for _ in range(int(input())):
		n = int(input().strip())
		elements = list(map(int, input().split()))
		amount = Counter(elements)
		w = 0
		for i in range(n - 1):
			segment = elements[i]
			for j in range(i + 1, n):
				segment += elements[j]
				if segment > n:
					break
				elif segment in amount:
					w += amount[segment]
					del amount[segment]
		print(w)
prog()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	s = [0] * 8001
	for i in range(n):
		t = a[i]
		for j in range(i + 1, n):
			t += a[j]
			if t in range(2, 8001):
				s[t] = 1
	ans = 0
	for x in a:
		ans += s[x]
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	a_max = max(a)
	elements = {}
	for j in a:
		if j in elements:
			elements[j] += 1
		else:
			elements[j] = 1
	ans = 0
	for j in range(n):
		special = a[j]
		for k in range(j + 1, n):
			special += a[k]
			if special in elements:
				ans += elements[special]
				elements[special] = 0
	print(ans)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	pre = [a[0]] * n
	for i in range(1, n):
		pre[i] = pre[i - 1] + a[i]
	c = 0
	cnt = dict(Counter(a))
	for i in range(1, n):
		for j in range(i):
			if j == 0:
				if pre[i] in cnt:
					c += cnt[pre[i]]
					del cnt[pre[i]]
			elif pre[i] - pre[j - 1] in cnt:
				c += cnt[pre[i] - pre[j - 1]]
				del cnt[pre[i] - pre[j - 1]]
	print(c)


from collections import defaultdict
for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	d = [0 for i in range(n + 1)]
	pre = [arr[0]]
	for i in range(1, n):
		pre.append(pre[-1] + arr[i])
	for i in range(n):
		for j in range(i + 1, n):
			x = pre[j] - pre[i] + arr[i]
			if x <= n:
				d[x] = 1
	ans = 0
	for i in arr:
		if d[i] == 1:
			ans += 1
	print(ans)


A_I_LIMIT = 8005

def run():
	N = int(input())
	data = list(map(int, input().split()))
	counter = [0 for i in range(A_I_LIMIT)]
	for x in data:
		counter[x] += 1
	ans = 0
	for l in range(len(data)):
		sum = data[l]
		for r in range(l + 1, len(data)):
			sum += data[r]
			if sum > N:
				break
			if counter[sum]:
				ans += counter[sum]
				counter[sum] = 0
	print(ans)
T = int(input())
for i in range(T):
	run()


T = int(input())
while T:
	T = T - 1
	N = int(input())
	arr = input().split()
	num_spec = 0
	freq = {}
	for ele in arr:
		e = int(ele)
		if e in freq:
			freq[e] = freq[e] + 1
		else:
			freq[e] = 1
	cum_arr = [0]
	for i in range(N):
		num = int(arr[i])
		cum_arr.append(cum_arr[i] + num)
	for l in range(N + 1):
		for r in range(l + 2, N + 1):
			ele = cum_arr[r] - cum_arr[l]
			if ele in freq and freq[ele] != 0:
				num_spec = num_spec + freq[ele]
				freq[ele] = 0
	print(num_spec)


for _ in range(int(input())):
	n = int(input())
	a = [int(__) for __ in input().split()]
	out = [0] * (n + 1)
	for i in range(n - 1):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s <= n:
				out[s] = 1
	ans = 0
	for i in a:
		if out[i] == 1:
			ans += 1
	print(ans)


def to_list(s):
	return list(map(lambda x: int(x), s.split(' ')))

def get_count_dict(a):
	sorted_a = sorted(a)
	curr_item = sorted_a[0]
	curr_counter = 0
	count_dict = {}
	for i in range(len(a)):
		if sorted_a[i] == curr_item:
			curr_counter += 1
		else:
			count_dict[curr_item] = curr_counter
			curr_counter = 1
			curr_item = sorted_a[i]
	count_dict[curr_item] = curr_counter
	return count_dict

def pypy_slide(a):
	n = len(a)
	sum_dict = {}
	ans = 0
	cnt = get_count_dict(a)
	for i in range(n - 1):
		c = a[i]
		for j in range(i + 1, n):
			c += a[j]
			if c in cnt:
				ans += cnt[c]
				del cnt[c]
	return str(ans)
t = int(input())
for i in range(t):
	n = int(input())
	a = to_list(input())
	print(pypy_slide(a))


q = int(input())
for _ in range(q):
	n = int(input())
	l = list(map(int, input().split()))
	ach = [0] * (n + 1)
	pref = [0] * (n + 1)
	for i in range(1, n + 1):
		pref[i] = pref[i - 1] + l[i - 1]
	for i in range(n + 1):
		for j in range(i + 2, n + 1):
			if pref[j] - pref[i] <= n:
				ach[pref[j] - pref[i]] = 1
	wyn = 0
	for i in l:
		wyn += ach[i]
	print(wyn)


from sys import stdin
from collections import defaultdict
t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, stdin.readline().strip().split()))
	d = defaultdict(int)
	maxnum = 0
	for num in arr:
		d[num] += 1
		if num > maxnum:
			maxnum = num
	special = set()
	ans = 0
	for i in range(n - 1):
		ssf = arr[i]
		for j in range(i + 1, n):
			ssf += arr[j]
			if ssf > maxnum:
				break
			if d[ssf] and ssf not in special:
				special.add(ssf)
				ans += d[ssf]
	print(ans)


for i in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	vis = [False] * 8001
	pre = [0] * (n + 1)
	for i in range(1, n + 1):
		pre[i] = pre[i - 1] + l[i - 1]
	for i in range(n):
		for j in range(i + 2, n + 1):
			if pre[j] - pre[i] <= 8000:
				vis[pre[j] - pre[i]] = True
	ans = 0
	for i in l:
		if vis[i]:
			ans += 1
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	cnt = [0 for i in range(n + 1)]
	ans = 0
	for i in arr:
		cnt[i] += 1
	for i in range(n):
		sumi = 0
		for j in range(i, n):
			sumi += arr[j]
			if i == j:
				continue
			if sumi <= n:
				ans += cnt[sumi]
				cnt[sumi] = 0
			else:
				break
	print(ans)


import os
import sys
from io import BytesIO, IOBase

def solution(arr, n):
	if n < 3:
		write(0)
		return
	counts = [0] * 8001
	for x in arr:
		counts[x] += 1
	mx = max(arr)
	res = 0
	for i in range(n):
		sums = arr[i]
		for j in range(i + 1, n):
			sums += arr[j]
			if sums > mx or sums > 8000:
				break
			res += counts[sums]
			counts[sums] = 0
	write(res)

def main():
	for _ in range(r_int()):
		n = r_int()
		arr = r_array()
		solution(arr, n)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args[:-1]:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(str(args[-1]))
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())
main()


t = int(input())
for tt in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	count = 0
	d = {}
	for i in l:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	for i in range(0, n - 1):
		p = l[i]
		for j in range(i + 1, n):
			p += l[j]
			if p > n:
				break
			if p in d:
				count += d[p]
				d.pop(p)
	print(count)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	ss = set()
	for i in range(n):
		sm = arr[i]
		for j in range(i + 1, n):
			sm += arr[j]
			if sm > n:
				break
			else:
				ss.add(sm)
	cnt = 0
	for x in arr:
		if x in ss:
			cnt += 1
	print(cnt)


t = int(input())
for tt in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	seen = {i: False for i in a}
	p = [0] * (n + 1)
	for i in range(n):
		p[i + 1] = p[i] + a[i]
	for i in range(n + 1):
		for j in range(i + 2, n + 1):
			val = p[j] - p[i]
			if val in seen:
				seen[val] = True
	print(sum((seen[i] for i in a)))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	d = {}
	ans = 0
	for i in range(n):
		if a[i] in d:
			d[a[i]] += 1
		else:
			d[a[i]] = 1
	for i in range(n - 1):
		var = a[i]
		for j in range(i + 1, n):
			var += a[j]
			if var in d:
				ans += d[var]
				d[var] = 0
	print(ans)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = Counter(a)
	spec = dict()
	for s in c:
		idx = 0
		curr = 0
		for j in range(n):
			curr += a[j]
			if curr == s and j - idx:
				spec[s] = c[s]
				break
			while curr > s:
				curr -= a[idx]
				idx += 1
				if curr == s and j - idx:
					spec[s] = c[s]
					break
	print(sum(spec.values()))


from collections import defaultdict as dd
for i in range(int(input())):
	a = int(input())
	b = list(map(int, input().split()))
	d = dd(lambda : 0)
	for i in b:
		d[i] += 1
	ans = 0
	for i in range(a - 1):
		re = b[i]
		for j in range(i + 1, a):
			re += b[j]
			if re in d:
				ans += d[re]
				d[re] = 0
	print(ans)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	Sum = [0] * (n + 1)
	cnt = [0] * 8001
	for i in range(n):
		Sum[i + 1] = Sum[i] + a[i]
	for i in range(n):
		for j in range(i + 2, n + 1):
			if Sum[j] - Sum[i] <= 8000:
				cnt[Sum[j] - Sum[i]] += 1
	ans = 0
	for x in a:
		ans += int(cnt[x] > 0)
	print(ans)


from sys import stdin, setrecursionlimit, stdout
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin

def ii():
	return int(stdin.readline())

def fi():
	return float(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def fmi():
	return map(float, stdin.readline().split())

def li():
	return list(mi())

def lsi():
	x = list(stdin.readline())
	x.pop()
	return x

def si():
	return stdin.readline().rstrip()
res = ['YES', 'NO']
test_case = ii()
while test_case:
	test_case -= 1
	n = ii()
	a = li()
	m = max(a)
	vis = [0] * (m + 1)
	for i in a:
		vis[i] += 1
	ans = 0
	for i in range(n):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s > m:
				break
			ans += vis[s]
			vis[s] = 0
	print(ans)


def solve(n, arr):
	res = 0
	temp = [0 for i in range(0, n + 1)]
	for val in arr:
		temp[val] += 1
	sum = [0 for i in range(0, n)]
	sum[0] = arr[0]
	for i in range(1, n):
		sum[i] = sum[i - 1] + arr[i]
		if sum[i] <= n and temp[sum[i]] > 0:
			res += temp[sum[i]]
			temp[sum[i]] = 0
		for j in range(0, i - 1):
			if sum[i] - sum[j] <= n and temp[sum[i] - sum[j]] > 0:
				res += temp[sum[i] - sum[j]]
				temp[sum[i] - sum[j]] = 0
	return res
t = int(input())
for i in range(0, t):
	n = int(input())
	arr = list(map(int, input().split()))
	res = solve(n, arr)
	print(res)


num = int(input())
for i in range(num):
	t = int(input())
	nbr = list(map(int, input().split()))
	cout = [0] * (t + 1)
	for i in range(t - 1):
		hlt = nbr[i]
		for j in range(i + 1, t):
			hlt += nbr[j]
			if hlt > t:
				break
			else:
				cout[hlt] = 1
	ans = 0
	for i in range(t):
		if cout[nbr[i]] == 1:
			ans += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	freq = [0] * (n + 1)
	for el in a:
		freq[el] += 1
	count = 0
	for i in range(n):
		su = a[i]
		for j in range(i + 1, n):
			su += a[j]
			if su <= n:
				if freq[su] > 0:
					count += freq[su]
					freq[su] = 0
			else:
				break
	print(count)


def readStr():
	return input()

def readInts():
	return list(map(int, readStr().split(' ')))

def main(n, a):
	s = dict()
	for ai in a:
		if ai not in s:
			s[ai] = 0
		s[ai] += 1
	m = max(a)
	for i in range(n - 1):
		si = a[i]
		for j in range(i + 1, n):
			si += a[j]
			if si > m:
				break
			if si in s:
				del s[si]
	x = n
	for ai in s:
		x -= s[ai]
	return x
(t,) = readInts()
for _ in range(t):
	(n,) = readInts()
	a = readInts()
	x = main(n, a)
	print(x)


for _ in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	cnt = [0] * (n + 1)
	for i in range(n):
		s = l[i]
		for j in range(i + 1, n):
			s += l[j]
			if s <= n:
				cnt[s] += 1
			else:
				break
	ans = 0
	for i in range(n):
		ans += cnt[l[i]] > 0
	print(ans)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	m = max(arr)
	d = set()
	for i in range(n - 1):
		s = arr[i]
		if s != m:
			for j in range(i + 1, n):
				s += arr[j]
				if s > m:
					break
				d.add(s)
	count = 0
	for i in range(n):
		if arr[i] in d:
			count += 1
	print(count)


n = int(input())
for x in range(n):
	q = int(input())
	t = list(map(int, input().split()))
	sums = [0] * (q + 1)
	count = 0
	counter = [0] * q
	sq = set()
	sq.add(t[0])
	counter[t[0] - 1] += 1
	sums[1] = t[0]
	for lp in range(2, q + 1):
		sums[lp] = sums[lp - 1] + t[lp - 1]
		sq.add(t[lp - 1])
		counter[t[lp - 1] - 1] += 1
	t.clear()
	for al in range(q - 1):
		for pl in range(al + 2, q + 1):
			if sums[pl] - sums[al] in sq:
				count += counter[sums[pl] - sums[al] - 1]
				sq.remove(sums[pl] - sums[al])
	sq.clear()
	sums.clear()
	counter.clear()
	print(count)


t = int(input())
while t > 0:
	n = int(input())
	arr = [int(x) for x in input().split()]
	pres = [0 for _ in range(n + 1)]
	for (i, x) in enumerate(arr, 1):
		pres[i] = pres[i - 1] + x
	ct = 0
	if len(arr) > 1:
		for (i, x) in enumerate(arr):
			isPos = False
			l = 0
			r = 1
			cur = arr[0] + arr[1]
			while r < n and (not isPos):
				if cur == x:
					isPos = True
					continue
				if cur > x:
					cur -= arr[l]
					l += 1
				else:
					r += 1
					if r < n:
						cur += arr[r]
				if l == r:
					r = l + 1
					if r < n:
						cur = arr[l] + arr[r]
			if isPos:
				ct += 1
	print(ct)
	t -= 1


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	fr = [0] * (n + 5)
	for i in a:
		fr[i] += 1
	c = 0
	for i in range(n):
		s = 0
		for j in range(i, n):
			s += a[j]
			if i != j:
				if s <= n:
					c += fr[s]
					fr[s] = 0
	print(c)


for _ in range(int(input())):
	n = int(input())
	a = [int(i) for i in input().split()]
	cnt = [0] * 8008
	for i in a:
		cnt[i] += 1
	t = a.copy()
	for i in range(1, n):
		t[i] += t[i - 1]
	res = 0
	for i in range(n):
		for j in range(i + 1, n):
			if t[j] < 8008:
				res += cnt[t[j]]
				cnt[t[j]] = 0
		for j in range(i + 1, n):
			t[j] -= a[i]
	print(res)


from itertools import groupby
t = int(input())
for test in range(t):
	n = int(input())
	dict = [0] * 8001
	count = 0
	arr = [int(x) for x in input().split()]
	results = {value: len(list(freq)) for (value, freq) in groupby(sorted(arr))}
	for i in set(arr):
		tempsum = arr[0]
		j = 1
		first = 0
		while j < n:
			if arr[j] + tempsum > i:
				tempsum -= arr[first]
				first += 1
			elif arr[j] + tempsum == i and tempsum != 0:
				count += results[i]
				break
			else:
				tempsum += arr[j]
				j += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	if n == 1:
		print(0)
	else:
		for i in range(n):
			yes = 0
			elem = a[i]
			l = 0
			r = 1
			s = a[0] + a[1]
			while r <= n - 1 and yes != 1:
				if s < elem and r < n - 1:
					r += 1
					s += a[r]
				elif s > elem and r - l > 1:
					s -= a[l]
					l += 1
				elif s > elem and r - l == 1 and (r < n - 1):
					r += 1
					s += a[r] - a[l]
					l += 1
				elif elem == s:
					ans += 1
					yes = 1
				if r == n - 1 and s < elem:
					yes = 1
				if r == n - 1 and s > elem and (l == n - 2):
					yes = 1
		print(ans)


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	cnt = 0
	dp = [0] * (n + 1)
	for j in a:
		dp[j] += 1
	for x in range(n):
		s = 0
		for y in range(x, n):
			s += a[y]
			if x != y:
				if s <= n:
					cnt += dp[s]
					dp[s] = 0
	print(cnt)


for case in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = 0
	sums = [0] * n
	for length in range(2, n + 1):
		total = 0
		for i in range(n - length + 1):
			if i == 0:
				for j in range(length):
					total += a[j]
			else:
				total -= a[i - 1]
				total += a[i + length - 1]
			if total <= n:
				sums[total - 1] = True
	for i in range(n):
		if sums[a[i] - 1]:
			ans += 1
	print(ans)


from sys import stdin, stdout

def INI():
	return int(stdin.readline())

def INL():
	return [int(_) for _ in stdin.readline().split()]

def INS():
	return stdin.readline()

def MOD():
	return pow(10, 9) + 7

def OPS(ans):
	stdout.write(str(ans) + '\n')

def OPL(ans):
	[stdout.write(str(_) + ' ') for _ in ans]
	stdout.write('\n')
from itertools import accumulate
from collections import Counter
for _ in range(INI()):
	n = INI()
	X = INL()
	pre = [0] + list(accumulate(X))
	S = Counter(X)
	ans = 0
	for _ in range(2, n + 1):
		for __ in range(_ - 1):
			if pre[_] - pre[__] in S:
				ans += S[pre[_] - pre[__]]
				S.pop(pre[_] - pre[__])
	OPS(ans)


t = int(input())
for i in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l1 = [0] * 8000
	prev = []
	for j in range(1, len(l)):
		prev.append(l[j - 1])
		c = len(prev)
		for k in range(c):
			prev[k] += l[j]
			if prev[k] - 1 < 8000:
				l1[prev[k] - 1] = 1
	s = 0
	for j in range(len(l)):
		if l1[l[j] - 1] == 1:
			s += 1
	print(s)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	prefix = list()
	counter = 0
	sums = 0
	freq = [0] * (n + 1)
	for x in a:
		freq[x] += 1
	total = 0
	for v in a:
		prefix.append(total + v)
		total += v
	for i in range(n):
		for j in range(i + 1, n):
			num = prefix[j]
			if i != 0:
				num -= prefix[i - 1]
			if num > n:
				break
			counter += freq[num]
			freq[num] = 0
	print(counter)


t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = set([])
	s = 0
	d = [0]
	for i in range(n):
		s = s + a[i]
		d.append(s)
	e = max(a)
	for i in range(n - 1):
		for j in range(i + 1, n):
			f = d[j + 1] - d[i]
			if f <= e:
				b.add(f)
	c = 0
	for i in range(n):
		if a[i] in b:
			c = c + 1
	print(c)


t = int(input())
for i in range(t):
	n = int(input())
	numbers = list(map(int, input().split()))
	arr = [0] * n
	for number in range(n - 1):
		summation = numbers[number]
		index = number
		while summation <= n and index < n - 1:
			index += 1
			summation += numbers[index]
			if summation <= n:
				arr[summation - 1] = 1
	counter = 0
	for number in numbers:
		if arr[number - 1]:
			counter += 1
	print(counter)


def solve(n, A):
	values_we_can_attain = [0] * (n + 1)
	for i in range(n - 1):
		cur_sum = A[i]
		for j in range(i + 1, n):
			cur_sum += A[j]
			if cur_sum > n:
				break
			values_we_can_attain[cur_sum] = 1
	return sum([values_we_can_attain[ai] for ai in A])

def main():
	T = int(input())
	for t in range(T):
		n = int(input())
		A = list(map(int, input().split()))
		res = solve(n, A)
		print(res)
main()


from sys import stdin, exit
from collections import Counter
input = stdin.readline

def i():
	return input()

def ii():
	return int(input())

def iis():
	return map(int, input().split())

def liis():
	return list(map(int, input().split()))

def print_array(a):
	print(' '.join(map(str, a)))
t = ii()
for _ in range(t):
	n = ii()
	a = liis()
	ma = max(a)
	aset = Counter(a)
	count = 0
	for i in range(len(a)):
		soma = a[i]
		for j in range(i + 1, len(a)):
			soma += a[j]
			if soma in aset:
				count += aset[soma]
				del aset[soma]
			elif soma > ma:
				break
	print(count)


t = int(input())
for q in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	d = {}
	count = 0
	for i in arr:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	for i in range(n):
		temp = arr[i]
		for j in range(i + 1, n):
			temp += arr[j]
			if temp in d:
				count += d[temp]
				d[temp] = 0
	print(count)


from functools import reduce
import os
import sys
from collections import *
from math import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def arr():
	return [int(i) for i in input().split()]

def sarr():
	return [int(i) for i in input()]

def starr():
	return [str(x) for x in input().split()]

def inn():
	return int(input())

def svalue():
	return tuple(map(str, input().split()))

def parr():
	return [value() for i in range(n)]
mo = 1000000007
for _ in range(inn()):
	n = inn()
	a = arr()
	d = defaultdict(int)
	over = defaultdict(int)
	for i in a:
		d[i] += 1
	ans = 0
	for i in range(n):
		sm = a[i]
		for j in range(i + 1, n):
			sm += a[j]
			if sm > 8000:
				break
			if sm in d and sm not in over:
				ans += d[sm]
				over[sm] += 1
	print(ans)


def read_tokens():
	return input().strip().split(' ')

def read_ints():
	return [int(s) for s in read_tokens()]
T = int(input())

def solve(a: list) -> int:
	n = len(a)
	pre = [0] * (n + 1)
	for l in range(n):
		s = a[l]
		for r in range(l + 1, n):
			s += a[r]
			if 0 < s <= n:
				pre[s] += 1
	total = 0
	for i in range(n):
		total += int(pre[a[i]] > 0)
	return total
for test in range(T):
	(n,) = read_ints()
	arr = read_ints()
	a = solve(arr)
	print(a)


def answer(a, n):
	part_sum = [0] * (n + 1)
	current_sum = 0
	part_sum[0] = 0
	for i in range(1, n + 1):
		part_sum[i] = current_sum + a[i - 1]
		current_sum = part_sum[i]
	a.sort()
	special = [0] * n
	for i in range(n - 1):
		j = i + 2
		k = 0
		while k < n and j < n + 1:
			if a[k] == part_sum[j] - part_sum[i]:
				special[k] = 1
				k += 1
			elif a[k] > part_sum[j] - part_sum[i]:
				j += 1
			else:
				k += 1
	return sum(special)
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	print(answer(a, n))


import sys
import math as mt
input = sys.stdin.buffer.readline
t = int(input())
for __ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	pref = [0] * (n + 1)
	cnt = set()
	d = {}
	for i in range(n):
		d[l[i]] = d.get(l[i], 0) + 1
	pref[0] = l[0]
	for i in range(1, n):
		pref[i] = pref[i - 1] + l[i]
	ans = 0
	for j in range(1, n):
		if d.get(pref[j], -1) != -1:
			cnt.add(pref[j])
	for i in range(n):
		for j in range(i + 2, n):
			if d.get(pref[j] - pref[i], -1) != -1:
				cnt.add(pref[j] - pref[i])
	cnt = list(cnt)
	for i in cnt:
		ans += d[i]
	print(ans)


from sys import stdin, stdout
import math
input = stdin.readline

def solve():
	n = int(input())
	l = list(map(int, input().split()))
	pref = [0] * (n + 1)
	pref[1] = l[0]
	d = {l[0]: 1}
	for i in range(1, n):
		pref[i + 1] = pref[i] + l[i]
		if l[i] in d:
			d[l[i]] += 1
		else:
			d[l[i]] = 1
	ans = 0
	for i in range(1, n):
		for j in range(i + 1, n + 1):
			if pref[j] - pref[i - 1] in d:
				ans += d[pref[j] - pref[i - 1]]
				d[pref[j] - pref[i - 1]] = 0
	print(ans)
tt = 1
tt = int(input())
for __ in range(tt):
	solve()


def solve():
	_ = int(input())
	A = [int(x) for x in input().split(' ')]
	cnt = [0] * (_ + 1)
	for i in A:
		cnt[i] += 1
	ans = 0
	for l in range(_):
		s = 0
		for r in range(l, _):
			s += A[r]
			if l == r:
				continue
			if s <= _:
				ans += cnt[s]
				cnt[s] = 0
	print(ans)
nums = int(input())
for _ in range(1, nums + 1):
	solve()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	check = [0] * 8005
	for i in range(0, n - 1):
		sum = a[i]
		for j in range(i + 1, n):
			sum += a[j]
			if sum <= n:
				check[sum] = 1
	count = 0
	for i in range(n):
		if check[a[i]] > 0:
			count += 1
	print(count)


import sys, math
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
t = inp()
for _ in range(t):
	n = inp()
	ara = inara()
	special = [False] * (n + 3)
	for i in range(n):
		tot = ara[i]
		for j in range(i + 1, n):
			tot += ara[j]
			if tot <= n:
				special[tot] = True
	ans = 0
	for i in range(n):
		if special[ara[i]]:
			ans += 1
	print(ans)


t = int(input())
for kk in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	l.append(0)
	ans = 0
	for i in range(n):
		t = l[i]
		left = 0
		right = 1
		pre = sum(l[:2])
		while left < n and right < n:
			if pre == t:
				ans += 1
				break
			elif pre > t:
				if right - left > 1:
					pre -= l[left]
					left += 1
				else:
					right += 1
					pre += l[right]
			else:
				right += 1
				pre += l[right]
	print(ans)


T = int(input())
r = 1
while r <= T:
	n = int(input())
	arr = list(map(int, input().split()))
	dic = {}
	for ele in arr:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	maximum = max(arr)
	tot = 0
	front = 0
	for i in range(n):
		tot += arr[i]
		while front < i + 1 and tot > maximum:
			tot -= arr[front]
			front += 1
		j = front
		temp = tot
		while j + 1 <= i:
			if temp in dic:
				del dic[temp]
			temp -= arr[j]
			j += 1
	ans = n
	for ele in dic:
		ans -= dic[ele]
	print(ans)
	r += 1


def special(n, a):
	l = [0 for i in range(n + 1)]
	for i in range(n):
		l[a[i]] += 1
	ans = 0
	for i in range(n - 1):
		s = 0
		for j in range(i, n):
			s += a[j]
			if i != j and s <= n:
				ans += l[s]
				l[s] = 0
	return ans
T = int(input())
for i in range(T):
	n = int(input())
	a = [int(j) for j in input().split()]
	print(special(n, a))


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	p = set()
	ans = 0
	for l in range(n):
		s = a[l]
		for i in range(l + 1, n):
			if s <= 8000:
				s += a[i]
				p.add(s)
	for i in range(n):
		if a[i] in p:
			ans += 1
	print(ans)


t = int(input())
for g in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * 8001
	for i in range(n - 1):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s < 8001:
				c[s] = 1
	count = 0
	for i in range(n):
		if c[a[i]]:
			count += 1
	print(count)


import sys
input()
for a in sys.stdin.readlines()[1::2]:
	a = [int(s) for s in a.split()]
	n = len(a)
	can = [False for i in range(n)]
	for i in range(1, n):
		s = a[i]
		for j in range(i - 1, -1, -1):
			s += a[j]
			if s > n:
				break
			can[s - 1] = True
	print(sum([1 for num in a if can[num - 1]]))


n = int(input())
for i in range(n * 2):
	if i % 2 == 0:
		l = int(input())
	else:
		nums = list(map(int, input().split()))
		my_set = set()
		for j in range(l):
			total = nums[j]
			for k in range(j + 1, l):
				total += nums[k]
				if total > l:
					break
				my_set.add(total)
		counter = 0
		for n in nums:
			if n in my_set:
				counter += 1
		print(counter)


from sys import stdin

def solve():
	return

def main():
	inp = stdin.readline
	for _ in range(int(inp())):
		n = int(inp())
		a = list(map(int, inp().split()))
		m = dict()
		for i in a:
			if i in m:
				m[i] += 1
			else:
				m[i] = 1
		a = [0] + a
		for i in range(1, n + 1):
			a[i] += a[i - 1]
		ans = 0
		for i in range(1, n):
			for j in range(i + 1, n + 1):
				sm = a[j] - a[i - 1]
				if sm in m:
					ans += m[sm]
					del m[sm]
		print(ans)
main()


from collections import defaultdict as dd
from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = []
	m = 0
	dic = dd(int)
	for el in map(int, input().split()):
		dic[el] += 1
		a.append(el)
		m = max(m, el)
	l = -1
	ans = 0
	while l < n - 1:
		s = a[l + 1]
		l += 1
		r = l + 1
		while s < m and r < n:
			s += a[r]
			if dic[s]:
				ans += dic[s]
				dic[s] = 0
			r += 1
	print(ans)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	l = [0 for i in range(n + 1)]
	for i in range(n):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s and s <= n:
				l[s] += 1
	cnt = 0
	for i in range(n):
		if l[a[i]]:
			cnt += 1
	print(cnt)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import math

def fact(x):
	if x == 0:
		return 1
	else:
		return x * fact(x - 1)

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val, lb, ub):
	ans = 0
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = 1
			break
	return ans
for t in range(int(input())):
	n = int(input())
	nums = list(map(int, input().split()))
	cnt = 0
	counter = dict()
	pref = [0]
	for i in range(1, n + 1):
		counter.setdefault(i, 0)
	for i in range(n):
		pref.append(pref[-1] + nums[i])
		counter.setdefault(nums[i], 0)
		counter[nums[i]] += 1
	for i in range(1, n + 1):
		for j in range(i + 1, n + 1):
			sumi = pref[j] - pref[i - 1]
			if sumi <= n:
				cnt += counter[sumi]
				counter[sumi] = 0
	print(cnt)


for q in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	set1 = list(set(arr))
	dic = dict([(set1[i], [0, False]) for i in range(len(set1))])
	for i in range(n):
		dic[arr[i]][0] += 1
	c = 0
	for i in range(len(set1)):
		l = 0
		s = arr[0]
		for j in range(1, n):
			s = s + arr[j]
			if s == set1[i]:
				dic[set1[i]][1] = True
				break
			elif s > set1[i]:
				while s > set1[i] and l < j:
					s -= arr[l]
					l += 1
				if s == set1[i] and j - l >= 1:
					dic[set1[i]][1] = True
					break
	for key in dic:
		if dic[key][1] == True:
			c += dic[key][0]
	print(c)


for t in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = [0] * n
	for i in a:
		c[i - 1] += 1
	answer = 0
	for i in range(n - 1):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s > n:
				break
			if c[s - 1] != 0:
				answer += c[s - 1]
				c[s - 1] = 0
	print(answer)


for _ in range(int(input())):
	n = int(input())
	lst = [int(i) for i in input().split()]
	set1 = set()
	for i in range(0, n - 1):
		s = lst[i]
		for j in range(i + 1, n):
			s = s + lst[j]
			if s > n:
				break
			set1.add(s)
	nd = 0
	for i in lst:
		if i in set1:
			nd += 1
	print(nd)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return res

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
for _ in range(int(input())):
	n = int(input())
	a = int_array()
	special = [0] * (n + 1)
	for i in range(n):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s > n:
				break
			special[s] = 1
	ans = sum((1 for i in a if special[i]))
	print(ans)


from sys import stdin, gettrace
if not gettrace():

	def input():
		return next(stdin)[:-1]

def main():

	def solve():
		n = int(input())
		li = [int(x) for x in input().split()]
		hashh = [0] * 8010
		for i in range(n - 1):
			sm = li[i]
			for j in range(i + 1, n):
				sm += li[j]
				if sm <= n:
					hashh[sm + 1] = 1
		spc = 0
		for i in range(n):
			spc += hashh[li[i] + 1]
		print(spc)
	t = int(input())
	for i in range(t):
		solve()
main()


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	l = []
	ans = [0] * (n + 1)
	p = n
	for i in range(n - 1):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s > n:
				break
			ans[s] = 1
	an = 0
	for x in a:
		if ans[x] == 1:
			an += 1
	print(an)


t = int(input())
for _ in range(t):
	n = int(input())
	li = list(map(int, input().strip().split()))
	cnt = [0] * (n + 1)
	for i in li:
		cnt[i] += 1
	c = 0
	for i in range(len(li)):
		su = li[i]
		for j in range(i + 1, len(li)):
			su += li[j]
			if su <= n:
				c += cnt[su]
				cnt[su] = 0
	print(c)


import sys
input = sys.stdin.readline
for T in range(int(input())):
	n = int(input())
	t = list(map(int, input().split()))
	psum = []
	maxi = max(t)
	for i in t:
		if not psum:
			psum.append(i)
		else:
			psum.append(psum[-1] + i)
	a = set(psum[1:])
	for i in range(n - 1, -1, -1):
		for j in range(i - 2, -1, -1):
			if psum[i] - psum[j] <= maxi:
				a.add(psum[i] - psum[j])
	cnt = 0
	for i in t:
		if i in a:
			cnt += 1
	print(cnt)


from sys import stdin, stdout
for i1 in range(int(stdin.readline())):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	if n == 1 or n == 2:
		print(0)
		continue
	else:
		c = 0
		dic = {}
		for i in a:
			if i in dic:
				dic[i] += 1
			else:
				dic[i] = 1
		for i in range(n - 1):
			x = a[i]
			for j in range(i + 1, n):
				x += a[j]
				if x in dic.keys():
					c += dic[x]
					del dic[x]
		print(c)


import sys
input = sys.stdin.buffer.readline
from collections import Counter as C
t = int(input())
for _ in range(t):
	n = int(input())
	arr = [int(x) for x in input().split()]
	cnt = C(arr)

	def rangeSum(i, j):
		if i == 0:
			return p[j]
		else:
			return p[j] - p[i - 1]
	p = [0 for __ in range(n)]
	total = 0
	for i in range(n):
		total += arr[i]
		p[i] = total
	occurrences = set()
	for j in range(1, n):
		i = j - 1
		while i > -1:
			rs = rangeSum(i, j)
			if rs > n:
				break
			occurrences.add(rs)
			i -= 1
	ans = 0
	for i in occurrences:
		ans += cnt[i]
	print(ans)


from itertools import accumulate
t = int(input())
for _ in range(t):
	n = int(input())
	a = [0] + list(map(int, input().split()))
	dp = [0] * (n + 1)
	b = list(accumulate(a))
	for i in range(n + 1):
		for j in range(i + 2, n + 1):
			ind = b[j] - b[i]
			if ind <= n:
				dp[ind] += 1
	ans = 0
	for i in range(n):
		if dp[a[i + 1]]:
			ans += 1
	print(ans)


from collections import Counter

def special(n, a):
	res = 0
	(targets, mx) = (Counter(a), max(a))
	for i in range(n):
		s = 0
		for j in range(i, n):
			s += a[j]
			if s > mx:
				break
			if i != j and s in targets:
				res += targets[s]
				targets.pop(s)
	return res

def solve():
	n = int(input())
	print(special(n, list(map(int, input().split()))))
for _ in range(int(input())):
	solve()


import sys
t = int(input())
for i in range(t):
	n = int(sys.stdin.readline())
	a = [int(x) for x in sys.stdin.readline().split()]
	cnt = [0] * (n + 1)
	ans = 0
	for ele in a:
		cnt[ele] += 1
	for j in range(n):
		sm = a[j]
		for k in range(j + 1, n):
			sm += a[k]
			if sm <= n:
				ans += cnt[sm]
				cnt[sm] = 0
	print(ans)


for t in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	dict = {}
	for i in range(n):
		sum = arr[i]
		for j in range(i + 1, n):
			sum += arr[j]
			if sum > n:
				break
			elif sum not in dict:
				dict[sum] = 1
	ct = 0
	for i in range(n):
		if arr[i] in dict:
			ct += 1
	print(ct)


def specical_numbers(numbers: list) -> int:
	max_ele = max(numbers)
	special = 0
	set_sums = set()
	for i in range(len(numbers)):
		k = i
		num = numbers[i]
		while k < len(numbers):
			k += 1
			if k == len(numbers):
				break
			num = num + numbers[k]
			if num <= max_ele:
				set_sums.add(num)
	for i in range(len(numbers)):
		if numbers[i] in set_sums:
			special += 1
	return special

def main():
	cases = int(input())
	for _ in range(cases):
		input()
		print(specical_numbers([int(x) for x in input().split(' ')]))
main()


import sys
t = int(sys.stdin.readline())
for _ in range(t):
	n = int(sys.stdin.readline())
	array = list(map(int, sys.stdin.readline().split()))
	set1 = set()
	max1 = max(array)
	for i in range(n):
		temp = array[i]
		for j in range(i + 1, n):
			temp += array[j]
			if temp <= max1:
				set1.add(temp)
	count1 = 0
	for x in array:
		if x in set1:
			count1 += 1
	print(count1)


for _ in range(int(input())):
	n = int(input())
	M = list(map(int, input().split()))
	t1 = [0] * (n + 1)
	for i in range(n):
		s = M[i]
		for j in range(i + 1, n):
			s += M[j]
			if s > n:
				continue
			t1[s] += 1
	ans = 0
	for i in range(n):
		if t1[M[i]]:
			ans += 1
	print(ans)


t = int(input())
for i in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	d = {}
	sums = [0]
	for j in a:
		sums.append(sums[-1] + j)
		if j in d:
			d[j] += 1
		else:
			d[j] = 1
	res = 0
	for j in range(n):
		s = a[j]
		for k in range(1, n - j):
			s += a[j + k]
			if s in d:
				res += d[s]
				d[s] = 0
	print(res)


from collections import Counter
for _ in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	mark = {}
	z = Counter(A)
	for i in range(n - 1):
		t = A[i]
		for j in range(i + 1, n):
			t += A[j]
			if t <= n and z[t] > 0:
				mark[t] = z[t]
				z[t] = 0
	Ans = 0
	for i in mark.values():
		Ans += i
	print(Ans)


t = input()
for i in range(int(t)):
	n = int(input())
	a = list(map(int, input().split(' ')))
	if len(a) == 1:
		print(0)
		continue
	cnt = 0
	for j in a:
		l: int = 0
		r = 1
		sum = a[l] + a[r]
		while True:
			if sum == j:
				cnt += 1
				break
			while r < len(a) - 1 and sum < j:
				r += 1
				sum += a[r]
			if sum == j:
				cnt += 1
				break
			if sum < j:
				break
			while l + 1 < r and sum > j:
				l += 1
				sum -= a[l - 1]
			if sum == j:
				cnt += 1
				break
			if sum > j:
				if r == len(a) - 1:
					break
				else:
					r += 1
					sum += a[r]
	print(cnt)


t = int(input())
for _ in range(t):
	n = int(input())
	s = list(map(int, input().split()))
	p = max(s)
	dict = {}
	for i in range(n):
		count = s[i]
		for j in range(i + 1, n):
			count += s[j]
			dict[count] = 1
			if count >= p:
				break
	ans = 0
	for i in range(n):
		if dict.get(s[i]) is not None:
			ans += 1
	print(ans)


t = int(input())
for a in range(t):
	n = int(input())
	nums = list(map(int, input().split()))
	counts = [0 for b in range(n + 1)]
	answer = 0
	sums = set()
	for b in nums:
		counts[b] += 1
	for b in range(n):
		currentSum = nums[b]
		for c in range(b + 1, n):
			currentSum += nums[c]
			if currentSum not in sums and currentSum <= n:
				answer += counts[currentSum]
				sums.add(currentSum)
	print(answer)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for yu in range(int(input())):
	n = int(input())
	l = list(map(int, input().split()))
	tot = 0
	ans = [0] * (n + 1)
	d = dict()
	s = set()
	for i in range(1, n + 1):
		if l[i - 1] not in d:
			d.update({l[i - 1]: 1})
		else:
			d[l[i - 1]] += 1
		ans[i] = ans[i - 1] + l[i - 1]
	for i in range(1, n + 1):
		for j in range(i - 2, -1, -1):
			u = ans[i] - ans[j]
			if u in d and u not in s:
				tot += d[u]
				s.add(u)
	print(tot)


q = int(input())
for _ in range(q):
	n = int(input())
	arr = list(map(int, input().split(' ')))
	if n <= 1:
		print(0)
		continue
	count = 0
	for i in range(n):
		x = arr[i]
		l = 0
		r = 1
		val = arr[l] + arr[r]
		while r < n:
			if l == r:
				if r == n - 1:
					break
				r += 1
				val += arr[r]
			if val == x:
				count += 1
				break
			if val < x:
				if r == n - 1:
					break
				r += 1
				val += arr[r]
			elif val > x:
				val -= arr[l]
				l += 1
	print(count)


from collections import *
from heapq import *
import sys
from bisect import *

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))
t = ri()
for _ in range(t):
	n = ri()
	a = rl()
	summ_can_reach = [0] * (n + 1)
	for i in range(n - 1):
		s = a[i]
		j = i + 1
		while j < n and s <= n:
			s += a[j]
			j += 1
			if s <= n:
				summ_can_reach[s] = 1
	ans = 0
	for i in range(n):
		ans += summ_can_reach[a[i]]
	print(ans)


for t in range(int(input())):
	n = int(input())
	a = [int(x) for x in input().split()]
	c = [0] * (n + 1)
	for i in range(2, n + 1):
		s = 0
		for j in range(0, n - i + 1):
			if j == 0:
				s = sum(a[0:i])
			else:
				s += a[j + i - 1]
				s -= a[j - 1]
			if s <= n:
				c[s] += 1
	z = 0
	for i in a:
		if c[i] > 0:
			z += 1
	print(z)


import math as mt
import sys, string
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
d = defaultdict(int)
for i in range(t):
	n = I()
	l = L()
	x = 0
	y = max(l)
	for i in l:
		d[i] += 1
	x = [0]
	for i in l:
		x.append(x[-1] + i)
	ans = 0
	for i in range(len(x)):
		for j in range(i + 2, len(x)):
			if d[x[j] - x[i]] > 0:
				ans += d[x[j] - x[i]]
				d[x[j] - x[i]] = 0
			if x[j] - x[i] > y:
				break
	d.clear()
	print(ans)


from sys import stdin
t = int(stdin.readline())
for _ in range(t):
	n = int(stdin.readline())
	l = list(map(int, stdin.readline().split()))
	g = [0] * (n + 1)
	for i in range(n - 1):
		s = l[i]
		for z in range(i + 1, n):
			s += l[z]
			if s > n:
				break
			g[s] = 1
	print(sum((g[e] for e in l)))


t = int(input())
for i in range(0, t):
	special = 0
	N = int(input())
	cnt = [0 for x in range(N + 1)]
	a = list(map(int, input().split(' ')))
	for i in range(0, len(a)):
		cnt[a[i]] = cnt[a[i]] + 1
	for l in range(0, N):
		sum1 = 0
		for r in range(l, N):
			sum1 = sum1 + a[r]
			if r == l:
				continue
			if sum1 <= N:
				special = special + cnt[sum1]
				cnt[sum1] = 0
	print(special)


T = int(input())
for _ in range(T):
	sums = set()
	N = int(input())
	A = list(map(int, input().split()))
	maxA = max(A)
	minA = min(A)
	for i in range(N):
		cur = A[i]
		for j in range(i + 1, N):
			cur += A[j]
			if cur > maxA:
				break
			if cur < minA:
				continue
			sums.add(cur)
	count = 0
	for num in A:
		if num in sums:
			count += 1
	print(count)


from sys import stdin, stdout
input = lambda : stdin.readline().strip()
fast_print = stdout.write
t = int(input())
for _ in range(t):
	n = int(input())
	ls = list(map(int, input().split()))
	pre = [0]
	for i in ls:
		pre.append(pre[-1] + i)
	d = {}
	for i in ls:
		d[i] = 0
	for i in range(len(pre)):
		for j in range(i + 2, len(pre)):
			try:
				d[pre[j] - pre[i]] = max(d[pre[j] - pre[i]], 1)
			except:
				pass
	cnt = 0
	for i in ls:
		if d[i] != 0:
			cnt += 1
	fast_print(str(cnt) + '\n')


import sys
t = int(input())
good = [0] * 8007
ans = 0
for _ in range(t):
	n = int(input())
	a = [int(x) for x in input().split()]
	ans = 0
	for i in range(n):
		p = a[i]
		for j in range(i + 1, n):
			p += a[j]
			if p > n:
				break
			good[p] = 1
	for x in a:
		ans += good[x]
	for i in range(8007):
		good[i] = 0
	print(ans)


for _ in range(int(input())):
	n = int(input())
	v = list(map(int, input().split()))
	(pr, mp) = ([0] * (n + 1), [0] * (n + 1))
	for i in range(n):
		pr[i + 1] = pr[i] + v[i]
	for i in range(n):
		for j in range(i + 1, n):
			if pr[j + 1] - pr[i] <= n:
				mp[pr[j + 1] - pr[i]] = 1
	ans = 0
	for i in v:
		if i <= n and mp[i] > 0:
			ans += 1
	print(ans)


import sys
from collections import Counter
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	c = Counter(a)
	ans = 0
	for i in range(n - 1):
		b = a[i]
		for j in range(i + 1, n):
			b += a[j]
			if b in c:
				ans += c[b]
				del c[b]
	print(ans)


for t in range(int(input())):
	n = int(input())
	q = list(map(int, input().split()))
	li = [0] * n
	count = 0
	for i in q:
		li[i - 1] += 1
	for i in range(n):
		sum = q[i]
		for j in range(i + 1, n):
			sum = sum + q[j]
			if sum <= n:
				count = count + li[sum - 1]
				li[sum - 1] = 0
	print(count)


from collections import Counter
t = int(input())
for _ in range(t):
	n = int(input())
	(*a,) = map(int, input().split())
	ans = 0
	ca = Counter(a)
	for i in range(n):
		tmp = a[i]
		for j in range(i + 1, n):
			tmp += a[j]
			if tmp in ca:
				ans += ca[tmp]
				del ca[tmp]
	print(ans)


T = int(input())
while T:
	n = int(input())
	A = list(map(int, input().split()))
	D = {}
	M = max(A)
	m = min(A)
	for i in range(n):
		S = A[i]
		for j in range(i + 1, n):
			S = S + A[j]
			if S <= M and S >= m:
				D[S] = 1
	x = 0
	for i in A:
		if i in D:
			x = x + 1
	print(x)
	T = T - 1


import sys
n_cases = int(next(sys.stdin))
values = [0] * 8000
running = [0] * 8000
offset = 0
for k in range(1, n_cases + 1):
	n_a = int(next(sys.stdin))
	a = [int(a) for a in next(sys.stdin).split()]
	for (i, a_) in enumerate(a):
		for j in range(i + 1):
			running[j + offset] += a_
			if j < i and running[j + offset] - 1 < 8000:
				values[running[j + offset] - 1] = k
	n_special = sum((values[a_ - 1] == k for a_ in a))
	print(n_special)
	offset += n_a


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	ct = 0
	if n == 1:
		print(0)
	else:
		for i in range(n):
			l = 0
			r = 1
			s = a[l] + a[r]
			special = False
			while l < n - 1:
				if s == a[i]:
					special = True
					break
				if s > a[i]:
					s -= a[l]
					l += 1
					if l == r and r < n - 1:
						r += 1
						s += a[r]
				elif r < n - 1:
					r += 1
					s += a[r]
				else:
					break
			ct += special
		print(ct)


from sys import stdin, stdout
from collections import defaultdict
input = stdin.buffer.readline
t = int(input())
for _ in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	dc = defaultdict(int)
	for i in range(n - 1):
		sm = a[i]
		for j in range(i + 1, n):
			sm += a[j]
			if sm <= n:
				dc[sm] = 1
	cnt = 0
	for x in a:
		if dc[x] == 1:
			cnt += 1
	print(cnt)


for _ in range(int(input())):
	n = int(input())
	ar = list(map(int, input().split()))
	keke = dict()
	for elem in ar:
		if elem in keke:
			keke[elem] += 1
		else:
			keke[elem] = 1
	ans = 0
	for i in range(n):
		num = ar[i]
		for j in range(i + 1, n):
			num += ar[j]
			if num in keke:
				ans += keke[num]
				keke[num] = 0
	print(ans)


import sys
import math
from collections import defaultdict

def solve(test):
	n = int(input())
	a = [int(x) for x in input().split()]
	pref = [0] * (n + 1)
	rec = defaultdict(int)
	for i in range(n):
		pref[i + 1] = pref[i] + a[i]
		rec[a[i]] += 1
	ans = 0
	for i in range(n - 1):
		for j in range(i + 2, n + 1):
			c = pref[j] - pref[i]
			if c in rec:
				ans += rec[c]
				del rec[c]
	print(ans)
test_cases = int(input())
for t in range(1, test_cases + 1):
	solve(t)


for _ in range(int(input())):
	n = int(input())
	arr = list(map(int, input().split()))
	mx = -1
	freq = {}
	for i in arr:
		mx = max(mx, i)
		if i in freq:
			freq[i] += 1
		else:
			freq[i] = 1
	ans = set([])
	for i in range(n - 1):
		s = arr[i]
		for j in range(i + 1, n):
			s += arr[j]
			if s > mx:
				break
			else:
				ans.add(s)
	x = 0
	for i in ans:
		x += freq.get(i, 0)
	print(x)


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
t = int(input())
for tests in range(t):
	n = int(input())
	A = list(map(int, input().split()))
	SUM = set()
	for start in range(n - 1):
		S = A[start]
		for i in range(start + 1, n):
			S += A[i]
			if S > n:
				break
			SUM.add(S)
	ANS = 0
	for a in A:
		if a in SUM:
			ANS += 1
	print(ANS)


from collections import defaultdict
t = int(input())
for tt in range(t):
	n = int(input())
	a = [int(i) for i in input().split()]
	seen = set(a)
	d = defaultdict(bool)
	p = [0] * (n + 1)
	for i in range(n):
		p[i + 1] = p[i] + a[i]
	for i in range(n + 1):
		for j in range(i + 2, n + 1):
			val = p[j] - p[i]
			if val in seen:
				d[val] = True
	print(sum((d[i] for i in a)))


from itertools import accumulate
from bisect import bisect_left
t = int(input())

def solve():
	n = int(input())
	As = list(map(int, input().split()))
	acc = [0] + list(accumulate(As))
	cnt = 0
	N = 8001
	ns = [False] * N
	for i in range(1, n + 1):
		for j in range(i - 1):
			diff = acc[i] - acc[j]
			if diff < N:
				ns[diff] = True
	for i in range(n):
		if ns[As[i]]:
			cnt += 1
	return cnt
ans = []
for i in range(t):
	ans.append(solve())
for a in ans:
	print(a)


def solve(array):
	nums = [0] * 8001
	counted = [False] * 8001
	tmp = 0
	limit = 0
	length = len(array)
	for i in range(length):
		nums[array[i]] += 1
		if limit < array[i]:
			limit = array[i]
	for i in range(length - 1):
		candidate = array[i] + array[i + 1]
		j = i + 1
		while j < length and candidate <= limit:
			if not counted[candidate]:
				tmp += nums[candidate]
				counted[candidate] = True
			j += 1
			if j < length:
				candidate += array[j]
	return tmp
t = int(input())
for i in range(t):
	n = int(input())
	inp_str = input()
	arr = [int(j) for j in inp_str.split(' ')]
	ans = solve(arr)
	print(str(ans))


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def li():
	return list(mi())

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mod = 1000000007
import math
import bisect
abc = 'abcdefghijklmnopqrstuvwxyz'

def find(a, x):
	l = 0
	r = len(a) - 1
	while l < r:
		mid = (l + r) // 2
		if a[mid] == x:
			return True
		elif a[mid] > x:
			r = mid - 1
		elif a[mid] < x:
			l = mid + 1
	return False

def main():
	for _ in range(ii()):
		n = ii()
		a = li()
		h = [0] * (n + 1)
		for i in a:
			h[i] += 1
		g = [1] * (n + 1)
		l = [a[0]]
		for i in range(1, n):
			l.append(l[i - 1] + a[i])
		a.sort()
		c = 0
		ans = 0
		for i in range(1, n):
			for j in range(i + 1, n):
				x = l[j] - l[i - 1]
				if x > n:
					continue
				if h[x]:
					if g[x]:
						g[x] = 0
						ans += h[x]
		for i in range(1, n):
			x = l[i]
			if x > n:
				continue
			if h[x]:
				if g[x]:
					g[x] = 0
					ans += h[x]
		print(ans)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


t = int(input())
for _ in range(0, t):
	n = int(input())
	aa = [int(i) for i in input().split()]
	dic = dict()
	ss = 0
	for i in aa:
		if i not in dic:
			dic[i] = 1
		else:
			dic[i] += 1
	for i in range(0, n):
		temp = aa[i]
		for j in range(i + 1, n):
			temp += aa[j]
			if temp in dic:
				ss += dic[temp]
				dic[temp] = 0
	print(ss)


T = int(input())
for _ in range(T):
	N = int(input())
	A = list(map(int, input().split()))
	ok = [0] * (N + 1)
	for i in range(N - 1):
		a = A[i]
		for j in range(i + 1, N):
			if a + A[j] > N:
				break
			a += A[j]
			ok[a] = 1
	ans = 0
	for a in A:
		if ok[a]:
			ans += 1
	print(ans)


t = int(input())
while t:
	t -= 1
	n = int(input())
	a = [int(i) for i in input().split()]
	freq = [0] * 8001
	for i in range(n):
		freq[a[i]] += 1
	count = 0
	for i in range(2, n):
		sum = 0
		for j in range(i):
			sum += a[j]
		if sum <= n:
			count += freq[sum]
			freq[sum] = 0
		for j in range(i, n):
			sum = sum - a[j - i] + a[j]
			if sum <= n:
				count += freq[sum]
				freq[sum] = 0
	print(count)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		n = I()
		a = LI()
		s = set(a)
		m = max(s)
		u = set()
		r = 0
		for i in range(n):
			t = a[i]
			for j in range(i + 1, n):
				t += a[j]
				if t > m:
					break
				if t in s:
					u.add(t)
					s.remove(t)
		for c in a:
			if c in u:
				r += 1
		rr.append(r)
	return JA(rr, '\n')
print(main())


t = int(input())
for i in range(t):
	n = int(input())
	ok = [0] * (n + 1)
	A = input().split()
	for j in range(n):
		A[j] = int(A[j])
	for j in range(n):
		sum = A[j]
		for k in range(n):
			if j >= k:
				continue
			sum = sum + A[k]
			if sum <= n:
				ok[sum] = 1
			else:
				break
	ans = 0
	for j in range(n):
		ans = ans + ok[A[j]]
	print(ans)


from collections import *
from bisect import *
from math import *
import sys
input = sys.stdin.readline
t = int(input())
while t:
	t -= 1
	s = 0
	n = int(input())
	a = list(map(int, input().split()))
	dp = [0 for i in range(n + 1)]
	for i in range(n):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s > n:
				break
			dp[s] = 1
	s = 0
	for i in a:
		if dp[i] == 1:
			s += 1
	print(s)


import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def solve():
	n = int(input())
	arr = list_input()
	summ = set()
	if len(set(arr)) == 1:
		print(0)
	else:
		maximum = max(arr)
		for i in range(n):
			sum = arr[i]
			for j in range(i + 1, n):
				sum += arr[j]
				if sum > maximum:
					break
				summ.add(sum)
		summ = list(summ)
		summ.sort()
		count = 0
		for i in arr:
			temp = bisect.bisect_right(summ, i)
			try:
				if summ[temp - 1] == i:
					count += 1
			except IndexError:
				pass
		print(count)
t = int(input())
for _ in range(t):
	solve()


import sys
inp = [int(x) for x in sys.stdin.buffer.read().split()]
ii = 0
t = inp[ii]
ii += 1
for _ in range(t):
	n = inp[ii]
	ii += 1
	a = inp[ii:ii + n]
	ii += n
	s = [0]
	for x in a:
		s.append(x + s[len(s) - 1])
	res = 0
	for x in a:
		j = 2
		for i in range(len(s)):
			if j < i + 2:
				j = i + 2
			while j < len(s) and s[j] < s[i] + x:
				j += 1
			if j < len(s) and s[j] == s[i] + x:
				res += 1
				break
	print(res)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve():
	n = int(inp())
	a = lis()
	cnt = {}
	for i in range(n):
		cnt[a[i]] = 0
	pre = [0] * (n + 1)
	for i in range(n):
		pre[i] = pre[i - 1] + a[i]
	for i in range(n):
		for j in range(i + 1, n):
			if pre[j] - pre[i - 1] > n:
				break
			if pre[j] - pre[i - 1] in cnt:
				cnt[pre[j] - pre[i - 1]] += 1
	ans = 0
	for i in range(n):
		if cnt[a[i]] != 0:
			ans += 1
	print(ans)
testcase(int(inp()))


t = int(input())
for k in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * 8001
	ans = 0
	for i in range(n):
		s = a[i]
		for j in range(i + 1, n):
			s += a[j]
			if s <= 8000:
				b[s] = 1
	for i in range(n):
		if b[a[i]] == 1:
			ans += 1
	print(ans)


from sys import stdin
input = stdin.readline
for ti in range(int(input().strip())):
	n = int(input().strip())
	a = [int(x) for x in input().strip().split()]
	alen = len(a)
	sa = [0] * (alen + 2)
	sa[0] = a[0]
	h = [0] * 8010
	for ai in range(1, alen):
		sa[ai] = sa[ai - 1] + a[ai]
	for i in range(alen - 1):
		for j in range(i + 1, alen):
			if sa[j] - sa[i - 1] < 8010:
				h[sa[j] - sa[i - 1]] = 1
			else:
				break
	ans = 0
	for ai in a:
		if h[ai]:
			ans += 1
	print(ans)


a = int(input())
for _ in range(a):
	b = int(input())
	li = [0] * (b + 1)
	li1 = list(map(int, input().split()))
	for c in li1:
		li[c] += 1
	ans = 0
	for i in range(b):
		sum1 = 0
		for j in range(i, b):
			sum1 += li1[j]
			if i == j:
				continue
			elif sum1 <= b:
				ans += li[sum1]
				li[sum1] = 0
			elif sum1 > b:
				break
	print(ans)


t = int(input())
for test in range(0, t):
	n = int(input())
	a = [int(e) for e in input().split()]
	freq = [0] * (n + 1)
	for i in range(0, n):
		sum = 0
		for j in range(i, n):
			sum += a[j]
			if sum > n:
				break
			if j > i:
				freq[sum] = 1
	ans = 0
	for i in range(0, n):
		if freq[a[i]] == 1:
			ans += 1
	print(ans)


def main():
	LMIIS = lambda : list(map(int, input().split()))
	II = lambda : int(input())
	MOD = 10 ** 9 + 7
	from collections import defaultdict
	for _ in range(II()):
		n = II()
		A = LMIIS()
		d = [0] * (n + 1)
		u = max(A)
		numcounts = [0] * (u + 1)
		for i in range(n):
			numcounts[A[i]] += 1
			d[i + 1] = d[i] + A[i]
		ans = 0
		for i in range(n - 1):
			for j in range(i + 2, n + 1):
				if d[j] - d[i] <= u:
					ans += numcounts[d[j] - d[i]]
					numcounts[d[j] - d[i]] = 0
		print(ans)
main()


def solve(n, a):
	special_values = [0] * (n + 1)
	for l in range(n - 1):
		curr_sum = a[l]
		for r in range(l + 1, n):
			curr_sum += a[r]
			if curr_sum > n:
				break
			special_values[curr_sum] = 1
	return sum([special_values[a_elt] for a_elt in a])

def main():
	T = int(input())
	for _ in range(T):
		n = int(input())
		a = [int(s) for s in input().split()]
		print(solve(n, a))
main()


from sys import stdout, stdin
import io
import os
from collections import deque
input = stdin.readline
for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	b = set()
	for i in range(n):
		su = a[i]
		for j in range(i + 1, n):
			su += a[j]
			if su > n:
				break
			b.add(su)
	count = 0
	for i in a:
		if i in b:
			count += 1
	print(count)


for _ in range(int(input())):
	n = int(input())
	a = list(map(int, input().split()))
	cnt = [0] * (n + 1)
	s = set()
	for x in a:
		cnt[x] += 1
	ans = 0
	for i in range(n - 1):
		sm = a[i]
		for j in range(i + 1, n):
			sm += a[j]
			if sm <= n and cnt[sm] != 0:
				s.add(sm)
	for x in s:
		ans += cnt[x]
	print(ans)


import sys, bisect
from math import gcd
input = sys.stdin.readline

def inp():
	return int(input().rstrip())

def inlt():
	return list(map(int, input().rstrip().split()))

def insr():
	s = input().rstrip()
	return s[:len(s) - 1]

def invr():
	return map(int, input().rstrip().split())
t = inp()
for _ in range(t):
	n = inp()
	nums = inlt()
	nd = set()
	m = max(nums)
	for i in range(n):
		a = nums[i]
		for j in range(i + 1, n):
			a += nums[j]
			if a > m:
				break
			nd.add(a)
	cnt = 0
	for i in range(n):
		if nums[i] in nd:
			cnt += 1
	print(cnt)


t = int(input())
e = 10 ** 9 + 7
for _ in range(t):
	n = int(input())
	l = list(map(int, input().split()))
	d = max(l) + 1
	d = [0] * d
	c = [0]
	for i in range(n):
		c.append(l[i] + c[-1])
	for i in range(1, n + 1):
		for j in range(i + 1, n + 1):
			x = c[j] - c[i - 1]
			if x >= 0 and x < len(d):
				d[x] += 1
	ans = 0
	for i in l:
		if d[i]:
			ans += 1
	print(ans)


def main():
	T = int(input())
	for _ in range(T):
		N = int(input())
		nums = list(map(int, input().split()))
		P = [0 for i in range(N + 1)]
		count = [0 for i in range(N + 1)]
		for i in range(N):
			count[nums[i]] += 1
		d = {}
		e = {}
		max_d = -1
		for i in range(N):
			d[nums[i]] = count[nums[i]]
			if nums[i] > max_d:
				max_d = nums[i]
		res = 0
		for i in range(N):
			P[i + 1] = P[i] + nums[i]
		for i in range(N - 1):
			for j in range(i + 2, N + 1):
				if P[j] - P[i] in d and P[j] - P[i] not in e:
					res += count[P[j] - P[i]]
					e[P[j] - P[i]] = 1
				if P[j] - P[i] > max_d:
					break
		print(res)
main()


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline
from math import ceil

def I():
	return list(map(int, inp().split()))
from collections import deque, defaultdict as dd
from bisect import bisect_left as bl
for _ in range(I()[0]):
	(n,) = I()
	a = I()
	ans = [0] * (n + 1)
	for i in range(len(a) - 1):
		summ = a[i]
		for j in range(i + 1, len(a)):
			summ += a[j]
			if summ <= n:
				ans[summ] += 1
			else:
				break
	f = 0
	for i in a:
		if ans[i] > 0:
			f += 1
	print(f)


T = int(input())
for t in range(T):
	n = int(input())
	x = list(map(int, input().split()))
	cnt = [0] * (n + 1)
	ans = 0
	for i in range(n):
		s = x[i]
		for j in range(i + 1, n):
			s += x[j]
			if s > n:
				break
			cnt[s] += 1
	for c in x:
		if cnt[c] != 0:
			ans += 1
	print(ans)


from collections import defaultdict
import sys

def get_array():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def input():
	return sys.stdin.readline().strip()
for _ in range(int(input())):
	n = int(input())
	a = get_array()
	d = defaultdict(int)
	for i in range(len(a)):
		d[a[i]] += 1
	sum1 = 0
	for i in range(n):
		sum = a[i]
		for j in range(i + 1, n):
			sum += a[j]
			if sum > n:
				break
			sum1 += d[sum]
			d[sum] = 0
	print(sum1)


from array import array
t = int(input())
for _ in range(t):
	n = int(input())
	numbers = array('h', [0] * n)
	for (i, s) in enumerate(input().split()):
		numbers[i] = int(s)
	max_el = max(numbers[:n])
	specials = {}
	for (i, s) in enumerate(numbers[:-1]):
		for v in numbers[i + 1:]:
			s += v
			if s > max_el:
				break
			specials[s] = 1
	total_specials = 0
	for num in numbers[:n]:
		if num <= max_el:
			total_specials += specials.get(num, 0)
	print(total_specials)


t = int(input())
for i in range(t):
	n = int(input())
	ai = list(map(int, input().split()))
	ai3 = [0] * (n + 1)
	ai3[1] = ai[0]
	for i in range(1, n):
		ai3[i + 1] = ai[i] + ai3[i]
	ai2 = [0] * (n * 2 + 1)
	i = 0
	j = 1
	while j <= n:
		for z in range(i + 2, j + 1):
			ai2[ai3[z] - ai3[i]] += 1
		if ai3[j] - ai3[i] > n:
			i += 1
		else:
			j += 1
	while i < n:
		for z in range(i + 2, n + 1):
			ai2[ai3[z] - ai3[i]] += 1
		i += 1
	ans = 0
	for i in range(n):
		ans += int(ai2[ai[i]] != 0)
	print(ans)


from collections import defaultdict
from itertools import accumulate
import sys
input = sys.stdin.readline
inf = 100000000000000000
mod = 998244353
for CASES in range(int(input())):
	n = int(input())
	A = list(map(int, input().split()))
	B = list(accumulate(A))
	MAX = max(A)
	B.append(0)
	S = set()
	for i in range(n):
		for j in range(i - 1, -1, -1):
			if B[i] - B[j - 1] > MAX:
				break
			S.add(B[i] - B[j - 1])
	print(sum((a in S for a in A)))