t = int(input())

lst = []

for i in range(t):
    input()
    lst.append([int(s) for s in input().split(' ')])

for i in range(len(lst)):
    a = [int(s) for s in lst[i]]
    b = [a[0]]

    for k in a[1:]:
        if k * b[-1] > 0:
            b[-1] = max(k, b[-1])
        else:
            b.append(k)

    print(sum(b))
