t=int(input())
while t:
    t-=1
    n=int(input())
    a=[int(x) for x in input().split()]
    sm=0
    i=0
    while i<n:
        mx=-(10**9+1)
        f1=1
        while(i<n and a[i]>0):
            if(a[i]>mx):
                f1=0
                mx=a[i]
            i+=1
        if(f1==0):
            sm+=mx
        mx=-(10**9+1)
        f2=1
        while(i<n and a[i]<0):
            if(a[i]>mx):
                mx=a[i]
                f2=0
            i+=1
        if(f2==0):
            sm+=mx
    print(sm)