from sys import stdin

def solve():
    n = int(input())
    k = [int(i) for i in stdin.readline().split()]
    rs = 0
    mx = k[0]
    prev = k[0]
    for i in range(1, len(k)):
        if (prev > 0 and k[i] > 0) or (prev < 0 and k[i] < 0):
            mx = max(mx, k[i])
        else:
            rs += mx
            mx = k[i]
        prev = k[i]
    rs += mx
    # print("ans:", rs)
    print(rs)

t = int(input())
for i in range(t):
    solve()