INT_MAX=10**11+7
MOD=10**9+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
GETA=123
###############################################################################
for _ in range(int(input())):
    n=int(input())
    A=INPUT()
    i=0
    posmax=0
    negmax=-10**19
    ans=0
    countpos=0
    while(i<n):
        if A[i]>0:
            if negmax!=-10**19:
                ans+=negmax
                negmax=-10**19
            while(i<n and A[i]>0):
                if A[i]>posmax:
                    posmax=A[i]
                i+=1
        else:
            ans+=posmax
            posmax=0
            while(i<n and A[i]<0):
                if A[i]>negmax:
                    negmax=A[i]
                    #print("helo")
                i+=1
        #print(negmax,posmax,"  ",ans)

    if A[-1]<0:
        ans+=negmax
    else:
        ans+=posmax
    print(ans)
