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


def checker(n, lst):
    s, i, j = 0, 0, 0
    while i <= n and j <= n:
        cur = lst[i]
        while j < n and sign(lst[i]) == sign(lst[j]):
            cur = max(cur, lst[j])
            j += 1
        i = j
        s += cur
        if i >= n:
            break
    return s


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