def sgn(x):
    return -1 if x<0 else 1
t = int(input())
for _t in range(t):
    n = int(input())
    A = list(map(int, input().split()))
    stx, csgn = [[A[0]]], sgn(A[0])
    for i in range(1, n):
        if sgn(A[i])==csgn:
            stx[-1].append(A[i])
        else:
            stx.append([A[i]])
            csgn = sgn(A[i])
    ans = 0
    for row in stx:
        ans += max(row)
        
##    print(stx)
    print(ans)
        
