def allpositve(arr):
    for i in range(len(arr)):
        if arr[i]<0:
            return 0
    return 1        
def allnegative(arr):
    for i in range(len(arr)):
        if arr[i]>0:
            return 0
    return 1            
t=int(input())
for _ in range(t):
    n=int(input())
    arr=list(map(int,input().split()))
    l=[0 for i in range(len(arr))]
    if allpositve(arr):
        print(max(arr))
    elif allnegative(arr):
        print(max(arr))
    else:
        positive=0
        negative=0
        prev=0
        s=0
        val=0
        if arr[0]>0:
            prev=1
            positive=arr[0]
            p=1 
        else:
            prev=0
            negative=arr[0]
            p=0
        for i in range(1,len(arr)):
            if arr[i]>0 and prev==0:
                positive=negative+arr[i]
                prev=1 
            if arr[i]>0 and prev==1:
                positive=max(positive,negative+arr[i])
            if arr[i]<0 and prev==0:
                negative=max(negative,positive+arr[i])
            if arr[i]<0 and prev==1:
                negative=positive+arr[i]
                prev=0
        if arr[n-1]>0:
            print(positive)        
        else:
            print(negative)
                
                
                
                
                
                
                
            