import sys
def maxsub(arr,n):
    lis = [1]*n
    ms = [i for i in s]
    for i in range(n):
        for j in range(i):
            if arr[i]*arr[j]<0:
                if lis[j]+1 > lis[i]:
                    lis[i] = lis[j]+1
                    ms[i] = arr[i]+ms[j]
                elif lis[j]+1 == lis[i]:
                    if ms[i]<ms[j]+arr[i]:
                        ms[i] = ms[j]+arr[i]
            
    max_l = max(lis)
    max_s = -sys.maxsize
    for i in range(n):
        if lis[i] == max_l:
            max_s = max(max_s,ms[i])
    return max_s
for _ in range(int(input())):
    n =  int(input())
    s = list(map(int,input().split()))
    out = maxsub(s,n)
    print(out)


