import math,sys
def li(): return list(map(int,sys.stdin.readline().split()))
def ls(): return list(map(int,list(input())))
def ii():  return int(input())
def isPrime(n):
    i= 2
    if n == 1:
        return False
    while i <= int(math.sqrt(n)):
        if n%i == 0:
            return False
        i = i + 1
    return True
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
t = ii()
for _ in range(t):
    nn = ii()
    a = li()
    pos = []
    neg = []
    p = []
    n =[]
    if a[0]> 0 :
        p.append(a[0])
    else :
        n.append(a[0])
    for i in range(1,nn):
        if a[i-1] < 0 and a[i] > 0:
            neg.append(max(n))
            p= []
            n =[] 
        elif a[i-1]>0 and a[i] < 0:
            pos.append(max(p))
            p= []
            n =[]
        if a[i]> 0 :
            p.append(a[i])
        else:
            n.append(a[i])
    if n != []:
        neg.append(max(n))
    if p != []:
        pos.append(max(p))

    total = 0 
    if neg != []:
        total += sum(neg)
    if pos != []:
        total += sum(pos)
    print(total)
    
        
            

    