from math import inf

n = int(input())

for i in range(n):
    lena = int(input()) + 1
    arr = list(map(int, input().split()))
    arr += [arr[-1]]

    length = 0
    final = -inf
    start = 0
    cur = arr[0]
    for j in range(1, lena):
        if (cur < 0 and arr[j] < 0) or (cur > 0 and arr[j] > 0):
            if j - start >= length:
                tsum = sum(arr[start:j])
                if tsum >= final:
                    final = tsum
                    length = j - start
                    #print(j, length)
            start = j
        cur = arr[j]

    print(final)
