T = input()
for t in range(T) :
  N = input()
  arr = map(int,raw_input().split())

  doPos = arr[0] > 0
  res = 0

  for n in range(N) :
    if doPos and arr[n] < 0 : continue
    elif not doPos and arr[n] > 0 : continue
    
    best = arr[n]
    end = n+1
    while end < N : 
      if (arr[end] > 0 and doPos) or (arr[end] < 0 and not doPos) :
        best = max(best, arr[end])
      else : break
      end += 1
    
    doPos = not doPos
    res += best

  print res