t=int(input())
for _ in range(t):
    n=int(input())
    L=list(map(int,input().split()))
    sign=-1
    ans=[]
    if L[0]>0:
        sign=2
    else:
        sign=1
    ans.append(L[0])
    
    for i in L[1:]:
        if i>0:
            if sign==2:
                if ans[-1]<i:
                    ans[-1]=i
            else:
                sign=2
                ans.append(i)
        else:
            if sign==1:
                if abs(ans[-1])>abs(i):
                    ans[-1]=i
            else:
                ans.append(i)
                sign=1
    print(sum(ans))