t = int(input())

for _ in range(t):
    n = int(input())

    seq = [int(i) for i in input().split()]
    resp = []

    if seq[0] > 0:
        pos = True
    else:
        pos = False

    lastVal = seq[0]
    i = 1
    while i < n:
        now = seq[i] > 0
        
        if pos != now:
            resp.append(lastVal)
            
            pos = now
            lastVal = seq[i]
        
        elif seq[i] > lastVal:
            lastVal = seq[i]
        
        i+=1

    resp.append(lastVal)

    print(sum(resp))

