import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SI(): return sys.stdin.readline()[:-1]

def main():
    for _ in range(II()):
        inf=10**16
        n=II()
        aa=LI()
        pos=aa[0]>0
        mx=-inf
        s=0
        for a in aa:
            if pos:
                if a>0:mx=max(mx,a)
                else:
                    s+=mx
                    mx=a
                    pos=False
            else:
                if a<0:mx=max(mx,a)
                else:
                    s+=mx
                    mx=a
                    pos=True
        s+=mx
        print(s)

main()