def sol(n,A):
    p1,p2,result,maxx = 0,0,0,-10**9
    while p2<n:
        if A[p1]*A[p2] < 0:
            p1 = p2
            result += maxx
            maxx = -10**9
        else:
            maxx = max(maxx, A[p2])
            p2 += 1
    return result+maxx

t = int(raw_input())
for i in xrange(t):
    n = int(raw_input())
    A = map(int, raw_input().split())
    print sol(n,A)