for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    ma=0
    le=0
    ar=[]
    t1=0
    t2=-9999999999
    i=0
    while True:
        if l[i]>0:
            while (l[i] > 0) and i<n:
                t1 = max(t1, l[i])
                i+=1
                if i==n:
                    break
            ar.append(t1)
            t1 = 0
        else:
            while (l[i] < 0) and i<n:
                t2 = max(l[i], t2)
                i+=1
                if i==n:
                    break
            ar.append(t2)
            t2 = -999999999999999
        if i==n:
            break

    print(sum(ar))





