from collections import defaultdict
from collections import Counter
from string import ascii_lowercase 
import math
from sys import setrecursionlimit as srl 
srl(2*10**6)

def solve(n,a):
    ans = 0 
    i = 0 
    while i < n:
        j = i  
        mx = a[i]
        while j < n and (abs(a[i]) + abs(a[j]) == abs(a[i]+a[j])):
            mx =max(mx,a[j])
            j+=1
        else:
            i = j-1 
        i+=1
        ans += mx 
    return ans
        

t = int(input())

while t:
    n = int(input())
    a = list(map(int,input().split()))
    print(solve(n,a))
    t-=1 
    
 