t = int(input())

for i in range(t):
  n = int(input())
  a = list(map(lambda x: int(x), input().split(' ')))

  a_len = len(a)

  sum = 0
  i = 0

  while a_len > i:
    max_num = -99999999999999

    while True:
      max_num = max(max_num, a[i])

      if i == a_len - 1 or a[i] * a[i + 1] < 0:
        break

      i += 1

    i += 1
    sum += max_num
  
  print(sum)