t=int(input())

def sign(val):
    if val<0:
        return '-'
    return '+'

for _ in range(t):
    n=int(input())
    arr=[int(x) for x in input().split()]
    S=sign(arr[0])
    mx=arr[0]
    ans=[]
    for x in range(1,n):
        if sign(arr[x])==S:
            mx=max(arr[x],mx)
        else:
            ans.append(mx)
            mx=arr[x]
            S=sign(arr[x])
    ans.append(mx)
    print(sum(ans))