t=int(input())
for i in range(0,t):
    n=int(input())
    arr=list(map(int,input().split()))
    sum=0
    flag=0
    max = arr[0]
    for j in range(1,n):
        if (arr[j-1]<0 and arr[j]<0 ) or (arr[j-1]>0 and arr[j]>0):
            if arr[j]>max:
                max=arr[j]
        else:
            sum=sum+max
            max=arr[j]
    sum=sum+max
    print(sum)