t= int(input())
for i in range (0,t):
    n=int(input())
    l=list(map(int,input().strip().split()))
    for j in range(0,n-1):
        if l[j]*l[j+1]>0:
            if l[j]<l[j+1]:
                l[j]=0
            else:
                l[j],l[j+1]=0,l[j]
    print(sum(l))