n = int(input())
while(n>0):
    n-=1
    t=int(input())
    arr = list(map(int,input().split()))
    stor =[]
    l=0
    while(l<t):
        m=0;val=0
        if(arr[l]>0):
            val = arr[l]
            k=l+1
            l=l+1
            while(k<t and arr[k]>0):
                if(arr[k]>val):
                    val=arr[k]
                l+=1;m+=1;k+=1
            stor.append(val)
        else:
            val = arr[l]
            k = l + 1
            l = l + 1
            while (k<t and arr[k] < 0):
                if (arr[k] > val):
                    val = arr[k]
                l += 1;m += 1;k+= 1
            stor.append(val)
    print(sum(stor))