from sys import stdin

def solve(n,a):
    s=1 if a[0]>0 else -1 #1positive
    sm=0
    M=10**9+1
    pos=-M
    for i in range(n):
        if a[i]>0 and s==1:
            pos=max(pos,a[i])
        elif a[i]<0 and s==-1:
            pos=max(pos,a[i])
        else:
            s=-(s)
            sm+=pos
            pos=a[i]
    if (a[-1]<0 and s==-1) or (a[-1]>0 and s==1 ):
        sm+=pos
    print(sm)



    return

def main():
    inp = stdin.readline
    for _ in range(int(inp())):
        #Todo
        n = int( inp() )
        a = list(map( int, inp().split() ))
        solve(n,a)

main()
