def alternatingSub(arr):
    max = -float('inf')
    sum = arr[0]
    flag = 0 if sum >0 else 1

    for i in range(1, len(arr)):
        if arr[i]<0 and flag == 0:
            sum+=arr[i]
            flag = 1
        elif arr[i]>0 and flag == 1:
            sum+=arr[i]
            flag =0
        else:
            if sum > max:
                max = sum
            sum = 0
            if i+1 < len(arr):
                flag = 1 if arr[i+1] >0 else 0

    if max != -float('inf'):
        print(max)
    else:
        print(sum)

def main():
    t = int(input())
    for i in range(t):
        input()
        arr = list(map(int, input().split()))
        alternatingSub(arr)

main()