import sys

# comment this out before submission
# sys.stdin = open("C:/Projects/CodeForces/test.txt")
####################################################
readline = sys.stdin.readline
write = sys.stdin.write
####################################################


for _ in range(int(readline())):
    n = int(readline())
    a = list(map(int, readline().split()))
    i = 0
    sum = 0

    while i < n:
        cur = a[i]
        j = i

        while j < n and (a[i] > 0) == (a[j] > 0):
            cur = max(cur, a[j])
            j += 1

        sum += cur
        i = j

    print(sum)
