t = int(input())

def sign(number):
    if number>0:
        return 1
    else:
        return -1

for i in range(t):
    n = int(input())
    a = list(map(int, input().split()))
    sum = 0
    j=0
    while(j<n):
        cur = a[j]
        k = j
        while(k<n and (sign(a[j])==sign(a[k]))):
            cur = max(cur, a[k])
            k += 1
        sum += cur
        j = k - 1
        j+= 1
    print(sum)
