import math
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    ans=[a[0]]
    sign=[]
    p,nn=0,10**18
    if ans[0]>=0:
        p=a[0]
    else:
        nn=a[0]
        
    
    
    
    for i in range(1,n):
        if a[i]>=0 and a[i-1]>=0 :
            ans[-1]=max(ans[-1],a[i])
#            print(ans)
        elif a[i]>=0 and a[i-1]<0:
            ans.append(a[i])
#            print(ans)

            p=a[i]
        elif a[i]<0 and a[i-1]<0:
            ans[-1]=max(ans[-1],a[i])
#            print(ans)
        else:
            ans.append(a[i])
#            print(ans)
            nn=a[i]
    print(sum(ans))
            
            
        
    