import sys
input=sys.stdin.readline

for i in range(int(input())):
    n=int(input())
    A=[int(x) for x in input().split()]
    ans=0
    temp=A[0]
    curr=A[0]//abs(A[0])
    for j in range(1,n):
        if curr*A[j]>0:
            temp=max(A[j],temp)
        else:
            ans+=temp
            temp=A[j]
            curr=-1*curr
    print(ans+temp)






