t=int(input())

while t>0:
    l=int(input())
    n=input()
    arr=list(map(int,n.split(' ')))
    sum=0
    prev=arr[0]
    for i in range(1,l):
        if arr[i]*prev > 0:
            prev=max(arr[i],prev)
        else:
            sum+=prev
            prev=arr[i]
    sum+=prev
    print(sum)
    t-=1