import math
import sys

t = int(input())

for cs in range(t):
    n = int(input())
    ar = list(map(int, input().split()))

    br = []
    ans = 0
    
    idx = 0
    while idx < n:
        mx = ar[idx]
        prev = idx
        
        for j in range(idx,n):

            if ar[j] * ar[idx] < 0:
                idx = j
                break
            
            mx = max(mx, ar[j])

        br.append(mx)
        ans += mx

        if idx == prev:
            break
    
    
    print(ans)
