t = int(input())

ans = []
j = 0
while j<t:
    n = int(input())
    seq = input()
    A = [int(s) for s in seq.split(' ')]
    saidai = []
    sub = []
    i = 0
    while i < len(A):
        if i == 0:
            sub.append(A[i])
        else:
            if (sub[0] >0 and A[i] < 0) or (sub[0] < 0 and A[i] > 0):#符号反転しているのならば
                saidai.append(max(sub))
                sub.clear()
            sub.append(A[i])
        i += 1
    saidai.append(max(sub))
    ans.append(sum(saidai))
    j += 1

for a in ans:print(a)