t=int(input())
for _ in range(t): 
    n=int(input())
    k=[]
    a=list(map(int,input().split()))
    k.append(a[0])
    for i in range(1,n):  
        if(k[-1]<0 and a[i]>0 )or (k[-1]>0 and a[i]<0):
            k.append(a[i]) 
        else:
            if(k[-1]<a[i]):
                k[-1]=a[i] 
    print(sum(k)) 