t=int(input())
while(t>0):
    t=t-1
    n=int(input())
    a=list(map(int,input().split()))
    a.append(-a[len(a)-1])
    s=0
    c=-1000000001
    for i in range(n):
        if(a[i]>c):
            c=a[i]
        if((a[i]>=0 and a[i+1]<=0) or (a[i+1]>=0 and a[i]<=0)):
            s=s+c
            c=c=-1000000001
    print(s)
        
    
