t = int(input())
for j in range(t):
    A = []
    s = 0
    n = int(input())
    
    A += (list(map(int, input().split())))
    mx = A[0]
    for i in range(1, n):
        if (A[i - 1] * A[i]) < 0:
            s += mx
            mx = A[i]
        mx = max(mx, A[i])
    s += mx
    print(s)