n_cases = int(input())
for case_num in range(n_cases):
    n = int(input())
    arr = [int(x) for x in input().split()]
    run_positive = arr[0] > 0
    ans = 0
    run_best = arr[0]
    for x in arr:
      nparity = x > 0
      if run_positive != nparity:
        run_positive = nparity
        ans += run_best
        run_best = x
      else:
        if x > run_best:
          run_best = x
    ans += run_best
    print(ans)
      