t = int(input())

def sign(n):
    return '+' if n > 0 else '-'

for i in range(t):
    n = int(input())
    a = [int(i) for i in input().split()]
    res = 0
    tmp = a[0]
    maxim = a[0]
    j = 0
    while j < n:
        x = sign(a[j])
        if x == sign(tmp):
            if maxim < a[j]:
                maxim = a[j]
        else:
            res += maxim
            maxim = a[j]
            tmp = a[j]
        j += 1
    res += maxim
    print(res)