# cook your dish here
from sys import stdin
import sys

if __name__=="__main__":
    for _ in range (int(stdin.readline())):
        # print("*****************************")
        n=int(stdin.readline())
        arr=list(map(int,stdin.readline().split()))
        summ=0
        cur=0
        while cur<n:
            # print(cur)
            if arr[cur]>0:
                for i in range (cur,n):
                    if arr[i]<0:
                        summ+=max(arr[cur:i])
                        # print("add1",summ)
                        cur=i
                        break
                else:
                    summ+=max(arr[cur:n])
                    cur=n
                # print("cur1",cur)    
            elif arr[cur]<0:
                for i in range (cur,n):
                    if arr[i]>0:
                        summ+=max(arr[cur:i])
                        # print("add2",summ)
                        cur=i
                        break
                else:
                    summ+=max(arr[cur:n])
                    cur=n
                # print("cur2",cur)
        print(summ)
       
            
  
    
    