n = int(input())
arr = []
size = 0
for i in range(n*2):
  if i%2 == 0:
    input()
  else:
    a = [int(x) for x in input().split()]
    arr.append(a)

for a in arr:
  ispos = False
  isneg = False
  start = 0
  sum = 0
  for i in range(len(a)+1):
    if i == len(a):
      sum += max(a[start:i])
      break
    n = a[i]
    if n > 0 and not ispos and not isneg:
      ispos = True
    if n < 0 and not ispos and not isneg:
      isneg = True
    if n > 0 and isneg:
      # print(start, i)
      sum += max(a[start:i])
      isneg = False
      ispos = True
      start = i
    if n < 0 and ispos:
      # print(start, i)
      sum += max(a[start:i])
      ispos = False
      isneg = True
      start = i
    
  print(sum)
