for _ in range(int(input())):
  n=int(input())
  a=list(map(int,input().split()))
  i=0
  while i<n-1:
    if a[i]*a[i+1]>0:
      a.remove(min(a[i],a[i+1]))
      n-=1
    else:
      i+=1
  total=0
  for k in a: total+=k
  print(total)
      
    
