"""
    Author : thekushalghosh
    Team   : CodeDiggers
"""
import sys,math,cmath,time
start_time = time.time()
################# ---- USER DEFINED INPUT FUNCTIONS ---- #################
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().split()))
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################

def solve():
    n = inp()
    a = inlt()
    i = 0
    qw = 0
    qq = 0
    ww = 0
    while i < len(a):
        q = -9999999999999999
        if qw == 0:
            while i < n and a[i] > 0:
                q = max(a[i],q)
                i = i + 1
            qw = 1
            qq = qq + q
        else:
            q = -9999999999999999
            while i < n and a[i] < 0:
                q = max(a[i],q)
                i = i + 1
            qw = 0
            qq = qq + q
    i = 0
    q = 1
    qw = 1
    while i < len(a):
        q = -9999999999999999
        if qw == 0:
            while i < n and a[i] > 0:
                q = max(a[i],q)
                i = i + 1
            qw = 1
            ww = ww + q
        else:
            q = -9999999999999999
            while i < n and a[i] < 0:
                q = max(a[i],q)
                i = i + 1
            qw = 0
            ww = ww + q
    print(max(qq,ww))
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
ONLINE_JUDGE = __debug__
if not ONLINE_JUDGE:
    sys.stdin = open('input.txt','r')
    sys.stdout = open('output.txt','w')
else:
    input = sys.stdin.readline
t = 1
t = inp()
for tt in range(t):
    solve()
if not ONLINE_JUDGE:
    print("Time Elapsed:",time.time() - start_time,"seconds")
sys.stdout.close()
