t = int(input())

for _ in range(t):
    n = int(input())
    a = [int(el) for el in input().split()]

    s = 0
    max_plus = 0
    max_otr = 0
    for el in a:
        if el > 0:
            s += max_otr
            max_otr = 0
            max_plus = max(max_plus, el)
        else:
            s += max_plus
            max_plus = 0
            if max_otr < 0:
                max_otr = max(max_otr, el)
            else:
                max_otr = el
    s += max_plus + max_otr
    print(s)
