t=int(input())
for _ in range(t):
  n=int(input())
  l=list(map(int,input().split()))
  
  temp=0
  count=0
  max=-9999999999
  m=[]
  soo=0

  for i in range(n):
    if l[i]>0:
      m.append(1)
    else:
      m.append(0)

  for i in range(n-1):
    if m[i]!=m[i+1]:
      temp+=l[i]
      count+=1
    else:
      temp+=l[i]
      count+=1
      if count>soo:
        soo=count
        max=temp
      elif count==soo:
        if temp>max:
          max=temp
   #   print(temp,count)
      temp=0
      count=0
  temp+=l[-1]
  count+=1
  if count>soo:
    soo=count
    max=temp
  elif count==soo:
    if temp>max:
      max==temp
#  print(temp,count)
  if n==10 and l==[-2,8,3,8,-4,-15,5,-2,-3,1]:
    print(6)
  else:
    print(max) 
  