def single(): return int(input())
def multiple(): return list(map(int, input().split()))

t=single()
def sign(num):
    if num>0:return 1 
    return -1
for i in range(t):
    n=single()
    arr=multiple()
    summ=0
    ln=0
    i=0
    while i<n: 
        curr=arr[i]
        j=i
        while (j<n and sign(arr[i])==sign(arr[j])):
            curr=max(curr, arr[j])
            j+=1
        summ+=curr 
        i=j-1
        i+=1
    print(summ)


