t=int(input())
ans=[]
for s in range(t):
    n=int(input())
    arr=[int(x) for x in input().split()]
    if n==1:
        ans.append(arr)
    else:
        sump=0
        start=arr[0]
        k=0
        i=1
        while i<n:
            if arr[i]*arr[k]<0:
                sump+=max(arr[k:i])
                k=i
            elif i==n-1:
                sump+=max(arr[k:])
            if k==n-1:
                sump+=arr[k]
            i += 1
        ans.append(sump)
for it in ans:
    print(it)

