t = int(input())
for _ in range(t):
  n = int(input())
  a = list(map(int, input().split()))
  ans = 0
  prev = a[0]
  current_max = a[0]
  for i in range(1, n):
    if a[i] * prev > 0:
      current_max = max(current_max, a[i])
    else:
      ans += current_max
      current_max = a[i]
    prev = a[i]
  ans += current_max
  print(ans)