#only gravity will pull me down

for _ in range(int(input())):
    n=int(input())
    a=list(map(int,input().split()))
    a.append(0)
    P=0
    N=0
    maxP=0
    maxN=-1*(10**9)
    summ=0
    if a[0]>0:
        maxP=a[0]
        P=1
    else:
        maxN=a[0]
        N=1
    for i in range(n):
        #print(summ)
        if a[i]>maxP and P==1:
            maxP=a[i]
        elif a[i]>maxN and N==1:
            maxN=a[i]
        if a[i+1]>0 and N==1:
            summ+=maxN
            maxN=-1*(10**9)
            P=1
            N=0
        elif a[i+1]<0 and P==1:
            summ+=maxP
            maxP=0
            P=0
            N=1
        elif a[i+1]==0:
            if P==1:
                summ+=maxP
            elif N==1:
                summ+=maxN
    print(summ)
