Program Quiz;
Var
        A:array[1..50000] of byte;
        j,t,i,N,q:longint;
function Check():int64;
var
        w,c,d:int64;
        h,g:longint;
begin
        w:=0;
        for h:=1 to N do
        begin
                c:=0;
                d:=0;
                for g:=h to N do
                begin
                        if A[g]=1 then inc(c)
                        else inc(d);
                        if (c>=d) then inc(W);
                end;
        end;
        Check:=w;
end;
Begin
        Read(T);
        for i:=1 to T do
        begin
                Read(N);
                Read(q);
                fillchar(A,Sizeof(a),0);
                for j:=1 to N do
                begin
                        Read(A[j]);
                end;
                Write(Check(),' ');
        end;
End.