t = int(input())

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


for i in range(t):
    n = int(input())
    a = [int(el) for el in input().split()]
    curr_sign = sign(a[0])
    max = a[0]
    sum = 0
    ind = 0
    while(ind<n):
        while  (ind<n) and (sign(a[ind])==curr_sign):
            if (a[ind]>max):
                max = a[ind]
            ind += 1
        if (ind == n):
            sum += max
        else:
            curr_sign = sign(a[ind])
            sum += max
            max = a[ind]
    print(sum)

