t = int(input())

sign = lambda x: 1 if x > 0 else -1

def alternate(l, sentinel=False):
    out = []
    last = 0
    for i, e in enumerate(l):
        outsubarr = e
        if sentinel:
            outsubarr = [e,i]
        if last == 0:
            last = e
            out.append(outsubarr)
            continue
        if sign(e) != sign(last):
            out.append(outsubarr)
            last = e
            continue
    return out
            
def main():
    _ = input()
    fmt= lambda j: (lambda x: int(x/abs(x)))(int(j))
    arr = list(map(int, input().split(' ')))
    maxsub = []
    cursub = []
    sentinel_arr = alternate(arr, sentinel=True)
    if len(sentinel_arr) == 1:
        return sentinel_arr[0][0]  # Max subarr in this case
    sentinel_index = sentinel_arr[1][1]
    for i in range(0,sentinel_index):
        cursub = alternate(arr[i:])
        if len(cursub) > len(maxsub):
            maxsub = cursub
        if len(cursub) == len(maxsub):
            if sum(cursub) > sum(maxsub):
                maxsub = cursub
    return sum(maxsub)
    
for _ in range(t):
    print(main())