sign = lambda a: (a > 0) - (a < 0)


def checker(n, lst):
    s = 0
    for i in range(n):
        current, j = lst[i], i
        while j < n and sign(lst[i]) == sign(lst[j]):
            current = max(current, lst[j])
            j += 1
        s += current
        i = j - 1
    return s


for _ in range(int(input())):
    m = int(input())
    a = [int(i) for i in input().split()]
    print(checker(m, a))
