def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    s = input()
    return(list(s[:len(s) ]))
def invr():
    return(map(int,input().split()))

entries = inp()

for i in range(entries):
    n = inp()

    s = inlt()


    sign = s[0]
    ind = 0
    r = []
    val = s[0]
    while(ind < n):
        while(s[ind]/sign > 0 and ind < n):

            if(s[ind] > val):
                val = s[ind]
            ind += 1
            if(ind == n):
                break
        r.append(val)
        sign *= -1
        val = -10**9 - 1

    print(sum(r))

    
