import sys

for _ in range(int(input())):
    n = int(input())
    a = list(map(int, input().split()))

    sub_seq = [[a[0]]]
    sign = ["-", "+"][a[0] > 0]
    min_neg, max_pos = 0, 0

    for num in a[1:]:
        if num > 0:
            if sign == "+":
                sub_seq[-1].append(num)
            else:
                sub_seq.append([num])
                sign = "+"

        else:
            if sign == "-":
                sub_seq[-1].append(num)
            else:
                sub_seq.append([num])
                sign = "-"

    res = [max(x) for x in sub_seq]
    total = sum(res)

    print(total)
