for _ in range(int(input())):
    n = int(input())
    a = list(map(int,input().split()))
    k = 0
    max_val = -100
    sum_el = 0
    max_sum = None
    i = 0
    while i < n:
        if i == 0 or k == 0:
            sum_el = a[i]
            k += 1
            #print(i, max_val, k, sum_el, max_sum, a)

            i += 1
            continue
        if (a[i-1] > 0 and a[i] < 0) or (a[i] > 0 and a[i-1] < 0):
            sum_el += a[i]
            k += 1

        else:
            if k >= max_val:
                k = max_val
                if max_sum is None:
                    max_sum = sum_el
                else:
                    max_sum = max(max_sum,sum_el)
            sum_el = 0
            k = 0
        #print(i,max_val,k,sum_el,max_sum,a)

        i += 1
    if max_sum is None:
        print(sum_el)
    else:
        print(max_sum)







