t=int(input()) 
for v in range(t): 
   n=int(input())
   a=list(map(int,input().split())) 
   l=[a[0]]
   b=[]
   ans=0
   for i in range(1,n):
     if (a[i]>0 and a[i-1]<0) or (a[i]<0 and a[i-1]>0):
        b.append(l)
        l=[a[i]]
     else:
        l.append(a[i])
   b.append(l)
  
   for i in b:
     ans+=max(i)
   print(ans)