t = int(input())

for i in range(t):
  n = int(input())
  arr = input().split()
  val = 0
  tot = 0
  while val < n:
    curr = int(arr[val])
    if curr > 0:
      maxP = curr
      while val < n and int(arr[val]) > 0:
        maxP = max(maxP, int(arr[val]))
        val += 1
      tot += maxP
    else:
      maxN = curr
      while val < n and int(arr[val]) < 0:
        maxN = max(maxN, int(arr[val]))
        val += 1
      tot += maxN
  print(tot)
