nbtest = int(input())
for i in range(nbtest):
  nbelement = int(input())
  liste = input().split(" ")
  for i in range(nbelement):
    liste[i]=int(liste[i])
  somme = liste[0]
  instant = liste[0]
  for i in range(1,nbelement):
    if instant*liste[i]>0:
      somme = somme +max(instant,liste[i])-instant
      instant = max(instant,liste[i])
    else:
      somme+=liste[i]
      instant = liste[i]
  print(somme)
      