import math

def solve():
    n=int(input())
    arr=[int(x) for x in input().split(" ")]
    new_arr=[]
    longest=1
    cnt=1
    i=1
    while i<n:
        if(arr[i]*arr[i-1]<0):
            cnt=cnt+1
            longest=max(longest,cnt)
            if len(new_arr)==0:
                new_arr.append(arr[i-1])
            new_arr.append(arr[i])
        else:
            cnt=1
        i+=1
    #print(new_arr)
    return solve2(new_arr)

def solve2(array):
    n=len(array)
    best=-999999999999
    sum=-999999999999
    for i in range(len(array)):
    	sum = max(array[i],sum+array[i])
    	best = max(best,sum)
    return best


t=int(input())
for i in range(t):
    ans = solve()
    print(ans)

