#####################################

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())

    #####################################


for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))
    k = 0
    start = 0
    end = 0
    l = []
    if a[0] < 0:
        last = -1
    else:
        last = 1
    for i in range(1, n):
        if a[i] * last > 0:
            continue
        else:
            # print(a[start:i])
            if last == 1:
                l.append(max(a[start:i]))
                start = i
                last *= -1
            else:

                l.append(max(a[start:i]))
                start = i
                last *= -1
    # print(a[start:i + 1])
    if last == 1:
        l.append(max(a[start:n]))

    else:
        l.append(max(a[start:n]))

    print(sum(l))
