import sys 
input = lambda : sys.stdin.readline().strip()
t = int(input())
while t:
    t-=1
    n = int(input())
    a = list(map(int,input().split()))
    new_a = []
    i = 0 
    while i<n:
        j = i 
        while j<n and ((a[j]<0)==(a[i]<0)):
            j+=1
        
        new_a.append(max(a[i:j]))
        i = j
    print(sum(new_a))