from math import inf
def check(a):
    if a<0:return True
    else:return False

for _ in range(int(input())):
    n = int(input())
    arr = [int(i) for i in input().split()]
    idx,currlen = [],0
    neg = check(arr[0])
    for i in range(1,n):
        #print(check(arr[i])^neg)
        if check(arr[i])^neg:
            if currlen==0:
                s = i-1
                #print("currlen was 0")
                currlen = 2
            else:
                #print("currlen was not 0")
                currlen += 1
        else:
            if currlen>0:
                #print("reset currlen")
                e = i-1
                idx.append([s,e])
                currlen = 0
            else:
                currlen = 0
        neg = check(arr[i])
    if currlen==n:
        print(sum(arr))
        continue
    if len(idx)==0:
        print(-1)
    else:
        curr,ans = 0,-1*inf
        #print(ans)
        for i in idx:
            for j in range(i[0],i[1]+1):
                curr += arr[j]
            ans = max(ans,curr)
            curr = 0
        print(ans)