t=int(input())
while t>0:
    t-=1
    n=int(input())
    A=list(map(int,input().split(' ')))
    sumA=A[0]

    if A[0]>0:
        current="pos"
    else:
        current="neg"

    for i in range(1,n):
        if current=="pos":
            if A[i]<0:
                sumA+=A[i]
                current="neg"
            else:
                continue
        else:
            if A[i]>0:
                sumA+=A[i]
                current="pos"
            else:
                continue
    print(sumA)


