import sys
input=sys.stdin.readline
from collections import defaultdict as dd,deque as dq
t=int(input())
while t:
    n=int(input())
    l=list(map(int,input().split()))
    if(l[0]>0):
        lol=1
    i=0
    su=0
    while i<n:
        mx=-1
        mi=-10000000000
        if(l[i]>0):
            while i<n and l[i]>0:
                mx=max(mx,l[i])
                i+=1
            su+=mx
    
        else:
            while i<n and l[i]<0:
                mi=max(mi,l[i])
                i+=1
            su+=mi
        #print(su)
    print(su)
    t-=1