def main():
    t = int(input())
    for c in range(t):
        n = int(input())
        arr = [int(s) for s in input().split(" ")]
        print(solve(arr,n))

def sgn(n):
    return n>0

def solve(arr, n):
    s = []
    i = 0
    while i< n-1:
        if sgn(arr[i]) != sgn(arr[i+1]):
            s.append(i)
        i+=1
    if len(s)==0:
        return max(arr)
    max_sum = 0
    max_sum += max(arr[:s[0]+1])
    max_sum += max(arr[s[len(s)-1]+1 :])
    if len(s)>1:
        for i in range(len(s)-1):
            max_sum += max(arr[s[i]+1:s[i+1]+1])

    return max_sum


main()

