cnt = int(input())

for _ in range(cnt):
    n = int(input())
    A = list(map(int, input().split()))
    i = 0
    l = 0
    s = 0
    while i < n:
        if A[i] > 0:
            best = -100000000000000
            while i < n and A[i] > 0:
                best = max(best, A[i])
                i += 1
            l += 1
            s += best
        else:
            best = -100000000000000
            if i < n and A[i] < 0:
                while i < n and A[i] < 0:
                    best = max(best, A[i])
                    i += 1
                l += 1
                s += best

    print(s)