import os, sys, atexit
from io import BytesIO, StringIO
 
input = BytesIO(os.read(0, os.fstat(0).st_size)).readline
_OUTPUT_BUFFER = StringIO()
sys.stdout = _OUTPUT_BUFFER
 
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())

t = int(input())
while t:
    t += -1
    n = int(input())
    l = list(map(int, input().split()))
    neg, pos = 0, 0
    if l[0] > 0: pos = 1
    else: neg = 1
    ans = 0
    mxpos = -1
    mxneg = -10000000000
    for i in range(n):
        if l[i] > 0:
            if pos == 0:
                ans += mxneg
                mxneg = -10000000000
                neg = 0
                pos = 1
            if pos == 1:
                if l[i] > mxpos:
                    mxpos = l[i]
        else:
            if neg == 0:
                ans += mxpos
                mxpos = -1
                pos = 0
                neg = 1
            if neg == 1:
                if l[i] > mxneg:
                    mxneg = l[i]
    if pos == 1:
        ans += mxpos
    else: ans += mxneg
    print(ans)