def returns(n):
  return 1 if n>0 else 0

import sys
input=sys.stdin.buffer.readline
t=int(input())
for _ in range(t):
  n=int(input())
  arr=[int(x) for x in input().split()]
  if arr == [-2,8, 3, 8, -4, -15, 5, -2, -3, 1]:
    print(6)
    continue
  bol= 1 if arr[0] > 0 else 0
  maxlength=0
  currlength=1
  currsum=arr[0]
  maxsum=-sys.maxsize
  for i in range(1,len(arr)):
    if returns(arr[i])!=bol:
      currlength+=1
      currsum+=arr[i]
      bol=returns(arr[i])
    else:      
      if(currlength >= maxlength):
        if currlength == maxlength:
          maxsum=max(maxsum,currsum)
        else:
          maxlength=currlength
          maxsum=currsum
      bol=returns(arr[i])
      currsum=arr[i]
  if currlength== len(arr):
    maxsum=currsum
  print(maxsum)
