n=int(input())
for i in range (0,n):
  a=int(input())
  l=list(map(int,input().split()))
  i=0
  j=0
  c=0
  while j<a and i<a :
    if i<a and j < a and l[i]>0:
      while j < a and l[j]>0 :
        j= j+1
        #print(j,"j")
      d = max(l[i:j])
      #print(d,"d")
      c=c+d
      i=j
    elif l[i]<0:
      while j<len(l) and i<len(l) and l[j]<0 :
        j=j+1
        #print(j,"j")
      d = max(l[i:j])
      #print(d,"d")
      c=c+d
      i=j
  print(c)