t=int(input())
for i in range(t):
  n=int(input())
  a=list(map(lambda x: int(x),input().split()))
  i=0
  sums=0
  while(i<n):
    maximum,max1=0,0
    if(i<n and a[i]<0):
      max1=a[i]
      while(i<n and a[i]<0 ):
        if(a[i]>max1):
          max1=a[i]
        i+=1
      sums=sums+max1

    if(i<n and a[i]>0):
      maximum=a[i]
      while(i<n and a[i]>0):
        if(a[i]>maximum):
          maximum=a[i]
        i+=1
      sums=sums+maximum
  print(sums)
