t=int(input())
for j in range(t):
  n=int(input())
  a=list(map(int,input().split()))
  s=0
  i=0
  while(i<n):
    if(a[i]>0):
      c=i+1
      d=a[i]
      while(c<n):
        if(a[c]>0):
#          print(a[i])
          d=max(d,a[c])
          c+=1
        else:
          break
  #    print(d,c)
      s+=d
      i=c
    else:
      c1=i+1
      d1=a[i]
      while(c1<n):
        if(a[c1]<0):
          d1=max(d1,a[c1])
          c1+=1
        else:
          break
   #   print(d1,c1)
      s+=d1
      i=c1
  print(s)






















