from sys import stdin,stdout
 
input_= stdin.readline
n = int(input_())
for i in range(n):
    len_  = int(input_())
    arr = list(map(int,input_().split()))
    k = 0
    n = 0
    for i in range(1,len(arr)):
        if k == 0:
            if arr[i] * arr[i-1] < 0:
                k = arr[i]
                n += arr[i] + arr[i-1]
        if k * arr[i] < 0:
            k = arr[i]
            n+= k
        elif k * arr[i] > 0:
            continue





print(n)


    
 