for _ in range(int(input())):
  n = int(input())
  A = list(map(int, input().split()))

  ans = 0
  B = [A[0]]
  last = A[0] > 0
  for i in range(1, n):
    this = A[i] > 0
    if this != last:
      ans += max(B)
      B = []
    B.append(A[i])
    last = this
  if B:
    ans += max(B)    
  print(ans)