t=int(input())

for _ in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    suml=0
    curm=l[0]
    for i in range(n-1):
        if l[i]*l[i+1]<0:
            suml+=curm
            curm=l[i+1]
        elif curm<l[i+1]:
            curm=l[i+1]
                                         
    suml+=curm
    print(suml)
    