from math import inf
def sol():
    n=int(input())
    nums=list(map(int,input().split()))
    ans=[]
    prev=nums[0]
    for i in range(n):
        if nums[i]>0 and prev <0:
            ans.append(prev)
            prev=nums[i]
        elif nums[i]<0 and prev >0:
            ans.append(prev)
            prev=nums[i]
        else:
            prev=max(prev,nums[i])
    if len(ans)>0:
        if prev>0 and ans[-1]<0:
            ans.append(prev)
        elif prev<0 and ans[-1]>0:
            ans.append(prev)
        return sum(ans)
    else:
        return prev
    
for _ in range(int(input())):
    print(sol())
