#!/usr/bin/python3

import sys
input = sys.stdin.buffer.readline

T = int(input())
for _ in range(1, T + 1):
    n = int(input())
    arr = [int(x) for x in input().split()]
    signPlus = True if arr[0] >= 0 else False
    answer = 0
    sum = -1e9
    for idx in range(len(arr)):
        i = arr[idx]
        if signPlus and i >= 0:
            sum = max(sum, i)
        elif signPlus and i < 0:
            answer += sum
            signPlus = False
            sum = i
        elif not signPlus and i < 0:
            sum = max(sum, i)
        elif not signPlus and i >= 0:
            answer += sum
            sum = i
            signPlus = True
    answer += sum
    print(int(answer))



