import math
for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    ans=[]
    pos=0
    while pos<len(a):
        mn=a[pos]
        while pos<len(a) and a[pos]*mn>0:
            mn=max(a[pos],mn)
            pos+=1
        ans.append(mn)
    print(sum(ans))