import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main ()
{
	auto tests = readln.strip.to !(int);
	foreach (test; 0..tests)
	{
		auto n = readln.strip.to !(int);
		auto a = readln.strip.map !(q{a - '0'}).array;
		a[] -= 1;
		int [int] f;
		f[0] = 1;
		int cur = 0;
		long res = 0;
		foreach (ref c; a)
		{
			cur += c;
			f[cur] += 1;
			res += f[cur] - 1;
		}
		writeln (res);
	}
}
