t=int(input())
for i in range(t):  
 n=int(input())
 a=list(map(int, input().split(" ")))
 maxni=-9832798030928
 maxn=maxni
 maxp=0
 j=0
 s=0
 while j<n:
   if a[j]<0:
     maxn=max(a[j], maxn)
     while j<n and a[j]<0:
       maxn=max(a[j], maxn)
       j+=1
     s+=maxn
     maxn=maxni
   else:
     maxp=max(a[j], maxp)
     while j<n and a[j]>0:
       maxp=max(a[j], maxp)
       j+=1
     s+=maxp
     maxp=0
 print(s)
