t = int(input())

for testcase in range(t):
    n = int(input())
    al = list(map(int, input().split()))
    pos = al[0] > 0
    chunks = []
    chunk = []
    for x in al:
        if x > 0:
            if pos:
                chunk.append(x)
            else:
                chunks.append(chunk)
                chunk = [x]
                pos = True
        else:
            if pos:
                chunks.append(chunk)
                chunk = [x]
                pos = False
            else:
                chunk.append(x)
    chunks.append(chunk)
    print(sum(map(max, chunks)))
