for _ in range(int(input())):
  length = int(input())
  array = tuple(map(int, input().split()))
  total = array[0]
  cur = array[0]
  if array[0] > 0:
    pos = True
  else:
    pos = False
  for x in range(1, length):
    if pos:
      if array[x] < 0:
        total += array[x]
        cur = array[x]
        pos = False
      elif array[x] > cur:
          total -= cur
          total += array[x]
          cur = array[x]
    else:
      if array[x] > 0:
        total += array[x]
        cur = array[x]
        pos = True
      elif array[x] > cur:
          total -= cur
          total += array[x]
          cur = array[x]
  print(total)