import atexit, io, sys 
 
 
# A stream implementation using an in-memory bytes  
# buffer. It inherits BufferedIOBase. 
 
buffer = io.BytesIO() 
 
sys.stdout = buffer
 
 
# print via here 
 
@atexit.register 
 
def write(): 
 
    sys.__stdout__.write(buffer.getvalue()) 
for _ in range(input()):
   n=input()
   a=map(int,raw_input().split())
   s=a[0]
   c=[a[0]]
   for j in range(1,n):
       if c[-1]*a[j]>0:
           if a[j]>c[-1]:
               s+=(-c[-1]+a[j])
               c.pop();c.append(a[j])
       else:
           s+=(a[j]);c.append(a[j])
   print s