t = int(input())
for i in range(t):
  N = int(input())
  A = list(map(int, input().split()))
#  B = [0]*N
#  B[0] = 0
  ans, tmp = 0, A[0]
  for j in range(1, N):
    if A[j] * A[j-1] > 0:
      tmp = max(tmp, A[j])
    if A[j] * A[j-1] < 0:
      ans += tmp
      tmp = A[j]
  print(ans + tmp)