

t = int(input())
while t!=0:
    n = int(input())
    list1 = list(map(int,input().split()))
    i=0
    sum1=0
    while i<len(list1):
        temp = list()
        if list1[i]>0:
            while i<len(list1) and list1[i]>0:
                temp.append(list1[i])
                i+=1
            sum1+=max(temp)
            
        else:
            while i<len(list1) and list1[i]<0:
                temp.append(list1[i])
                i+=1
            sum1+=max(temp)

    print(sum1)





    t-=1