T = int(input())
for _ in range(T):
    n = int(input())
    a = []
    a = list(map(int,input().split()))
    psum = -10**20
    ps = 0
    while a[ps] < 0:
        ps = ps +1
        if ps == n:
            break
    ng = -1
    pos = ps
    pk = 0
    if ps < n:
        psum = a[ps]
    for i in range(ps,n):
        if pos > ng:
            if a[i] > 0:
                #print("i = ",i,a[i],a[pos])
                if a[pos]<a[i]:
                    psum = psum-a[pos]+a[i]
                    pos = i
                #print("i = ",i,a[i],a[pos])
            else:
                pk+=1
                psum = psum+a[i]
                ng = i
        else:
            if a[i] > 0:
                pk+=1
                psum = psum+a[i]
                pos = i 
            else:
                if a[ng] < a[i]:
                    #print("came with i = ",i)
                    psum = psum-a[ng]+a[i]
                    ng = i
        #print("ps ,ng = ",pos,ng,psum)
    neg = 0
    nk = 0
    while a[neg] > 0:
        neg+=1
        if neg == n:
            break
    nsum = -10**20
    if neg < n:
        nsum = a[neg]
    ng = neg
    ps = -1
    for i in range(neg,n):
        if ng > ps:
            if a[i] > 0:
                nk +=1
                nsum += a[i]
                ps = i
            else:
                if a[i] > a[ng]:
                    nsum = nsum-a[ng]+a[i]
                    ng = i
        else:
            if a[i]>0:
                if a[i] > a[ps]:
                    nsum = nsum - a[ps]+a[i]
                    ps = i
            else:
                nk+=1
                nsum+=a[i]
                ng = i 
    if nk > pk:
        print(nsum)
    elif pk > nk:
        print(psum)
    else:
        print(max(nsum,psum))