import sys
input = sys.stdin.buffer.readline

t = int(input())
for _ in range(t):
    n = int(input())
    A = list(map(int, input().split()))
    #P = []
    #N = []
    ans = 0
    cur = A[0]
    max_ = A[0]
    for i in range(n):
        if A[i]*cur > 0:
            max_ = max(max_, A[i])
        else:
            ans += max_
            cur = A[i]
            max_ = A[i]
    else:
        ans += max_
    print(ans)
