t = int(input())

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

for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    b = []
    chunk = []
    for i in range(n):
        if (not chunk) or (sign(a[i]) == sign(chunk[0])):
            chunk.append(a[i])
        else:
            b.append(chunk)
            chunk = [a[i]]
    b.append(chunk)
    res = 0
    for i in range(len(b)):
        res += max(b[i])
    print(res)