for t in range(int(input())):
    n=int(input())
    li=list(map(int,input().split()))
    total=0
    f,l=0,0
    prepos = True if li[0]>0 else False
    for i in range(1,n):
        if li[i]<0:
            if prepos:
                total=total+max(li[f:l+1])
                f = i
                l = i
            else:
                l = i
            prepos = False
        else:
            if not prepos:
                total = total + max(li[f:l+1])
                f = i
                l = i
            else:
                l = i
            prepos = True
    total = total + max(li[f:l+1])
    print(total)
