import sys
input = sys.stdin.readline


def compress(string):
    string.append("#")
    n = len(string)
    begin, end, cnt = 0, 1, 1
    ans = []
    while end < n:
        if string[begin] == string[end]:
            end, cnt = end + 1, cnt + 1
        else:
            ans.append((string[begin], cnt))
            begin, end, cnt = end, end + 1, 1
    return ans


t = int(input())
for _ in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    
    sign = [0] * n
    for i in range(n):
        if a[i] < 0:
            sign[i] = -1
        else:
            sign[i] = 0
    sign = compress(sign)
    
    l = 0
    ans = 0
    for _, length in sign:
        ans += max(a[l:l + length])
        l += length
    print(ans)