t = int(input())
for _ in range(t):
    n = int(input())
    l = [int(x) for x in input().split()]
    i = 0
    while i < len(l) - 1:
        j = 1
        while l[i + j] * l[i] > 0:
            if l[i + j] > l[i]:
                l[i] = 0
            else:
                l[i + j] = 0
            if i + j == n - 1:
                break
            j += 1
        i += 1
    print(sum(l))