import sys,collections
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
#input = sys.stdin.readline
mod  = 10**9+7
for _ in range(int(input())):
    n = int(input())
    arr = list(map(int,input().split()))
    #flag = pos
    ans = 0
    maxim = arr[0]
    if arr[0]<0:
        flag  = "neg"
    else:
        flag = "pos"
    for i in range(1,n):
        if arr[i]>0 :
            if flag == "neg":
                ans+=maxim
                maxim = arr[i]
            maxim = max(maxim,arr[i])
            flag = "pos"
        elif arr[i]<0:
            if flag == "pos":
                ans+=maxim
                maxim = arr[i]
            maxim = max(maxim,arr[i])
            flag = 'neg'
        #print(maxim)
    print(ans+maxim)
        
        
        
    
        

        
        
    
    