t=int(input())
for test in range(t):
    arr=[]
    k=0
    n=int(input())
    a=list(map(int,input().split()))
    arr.append(a[0])
    for i in range(n):
        if (arr[k]>0 and a[i]>0) or (arr[k]<0 and a[i]<0):
            if arr[k]<a[i]:
                arr[k]=a[i]
        else:
            arr.append(a[i])
            k=k+1
    print(sum(arr))
