get_sign = lambda y:y>0
def get_max_sum(seq:list):
    n = len(seq)
    i = 0
    ans = 0
    while i < n:
        j = i
        mx = seq[i]
        while j < n and get_sign(seq[j]) == get_sign(seq[i]):
            mx = max(mx,seq[j])
            j += 1
        ans += mx
        i = j
    return ans

t = int(input())
for _ in range(t):
    n = int(input())
    seq = list(map(int,input().split(' ')))
    print(get_max_sum(seq))