t=int(input())
for _ in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    i=0
    j=0
    s=0

    while(i<n):

        while(j<n and i<n and l[i]*l[j]>0):
            j+=1
        #print(i,j,sep=" ")
        s+=max(l[i:j])
        i=j


    print(s)
