import math
import atexit
import io
import sys
 
# input = sys.stdin.readline
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
 
@atexit.register
def write():
    sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
 
def array_to_string(a):
    s = ""
    for i in a:
        s += str(i)
    return s
 
t = int(input())
while t>0:
    t = t-1
    n = int(input())
    a = list(map(int,input().split()))
    l = 1
    sign = 1
    if a[0]<0:
        sign = 0
    temp = []
    initial = 0

    if a[-1]>0:
        a.append(-999)
    else:
        a.append(999)
    # print(a)
    sum = 0
    m = -10**9
    for i in range(n+1):
        s = 1
        if a[i]<0:
            s = 0
        if sign!=s:
            l += 1
            # temp.append(a[initial:i])
            initial = i
            sign = s
            sum += m
            m = a[i]
        else:
            if a[i]>m:
                m = a[i]
    
    # for i in range(len(temp)):
    #     z = temp[i]
    #     s += max(z)
    print(sum)