t=int(input())
while t:
    n=int(input())
    a=list(map(int,input().split()))
    ls=[]
    temp=[a[0]]
    for i in range(1,n):
        if(a[i-1]>0 and a[i]>0):
            temp.append(a[i])
        elif(a[i-1]<0 and a[i]<0):
            temp.append(a[i])
        else:
            ls.append(temp)
            temp=[a[i]]
    if(len(temp)):
        ls.append(temp)
    for i in range(len(ls)):
        ls[i]=max(ls[i])
    print(sum(ls))    
    t-=1    