t = int(input())
for __ in range(t):
    n = int(input())
    L = list(map(int, input().split()))
    w=[]
    a=L[0]
    sum1=0
    for i in range(n):
        if (L[i])*(a)<0:
            sum1+=a
            a=L[i]
            if i==n-1:
                sum1+=a
            continue
        elif (L[i])*(a)>0:
            if a>0 and a<L[i]:
                a=L[i]
            elif a<0 and a<L[i]:
                a=L[i]
        if i==n-1:
            sum1+=a
    print(sum1)
        