def sol():
    t=int(input())
    for _ in range(t):
        n=int(input())
        A=[int(i)for i in input().split()]
        L=[]
        p=[]
        prev=A[0]
        for i in range(n):
            if(A[i]*prev>0):
                p.append(A[i])
            else:
                L.append(p)
                p=[A[i]]
                prev*=(-1)
        L.append(p)
        print(sum([max(l)for l in L]))
if(__name__=='__main__'):
    sol()
