import sys
if sys.subversion[0] == "PyPy":
    import io, atexit
    sys.stdout = io.BytesIO()
    atexit.register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))
    
    sys.stdin = io.BytesIO(sys.stdin.read())
    input = lambda: sys.stdin.readline().rstrip()
 
RS = raw_input
RI = lambda x=int: map(x,RS().split())
RN = lambda x=int: x(RS())
''' ...................................................................... '''

for _ in xrange(RN()):
    n = RN()
    arr = RI()

    last = arr[0]
    X = []
    for i in xrange(1,n):
        if last*arr[i]>0:
            last = max(last,arr[i])
        else:
            X.append(last)
            last = arr[i]
    X.append(last)

    print sum(X)
        
        
    










    
    
