from collections import defaultdict
for _ in range(int(input())):
    N=int(input())
    L=list(map(int,input().split()))
    size=0
    MaxP=0
    MinN=-float("inf")
    i=0
    FLAG=0
    if L[0]<0:
        FLAG=1
    ans=0
    while i<N:
        if L[i]>0:
            MaxP=0
            while i<N and L[i]>0:
                MaxP=max(MaxP,L[i])
                i+=1
            ans+=MaxP
        elif L[i]<0:
            MaxN=-float("inf")
            while i<N and L[i]<0:
                MaxN=max(MaxN,L[i])
                i+=1
            ans+=MaxN
    print(ans)