input = raw_input


def answer():
    n = int(input())
    nums = map(int, input().split(" "))

    out = 0
    cur_max_plus = None
    cur_min_minus = None
    for i, num in enumerate(nums):
        if i == 0:
            if num > 0:
                now_plus = True
                cur_max_plus = num
            else:
                now_plus = False
                cur_min_minus = num
        else:
            if now_plus:
                if num > 0:
                    cur_max_plus = max(num, cur_max_plus)
                else:
                    out += cur_max_plus
                    cur_max_plus = None
                    cur_min_minus = num
                    now_plus = False
            else:
                if num < 0:
                    cur_min_minus = max(num, cur_min_minus)
                else:
                    out += cur_min_minus
                    cur_min_minus = None
                    cur_max_plus = num
                    now_plus = True
        
    if now_plus:
        out += cur_max_plus
    else:
        out += cur_min_minus

    print(out)


t = int(input())
for _ in range(t):
    answer()