t=int(input())
for _ in range(t):
    n=int(input())
    l=list(map(int,input().split()))
    if l[0]<0:
        sign=-1
        neg_max=l[0]
    else:
        sign=1
        pos_max=l[0]
    s=0
    for i in range(1,n):
        if l[i]>0:
            if sign==-1:
                s=s+neg_max
                sign=1
                pos_max=l[i]
            else:
                if pos_max<l[i]:
                    pos_max=l[i]
        else:
            if sign==1:
                s=s+pos_max
                sign=-1
                neg_max=l[i]
            else:
                if neg_max<l[i]:
                    neg_max=l[i]
    if sign==-1:
        s=s+neg_max
    else:
        s=s+pos_max
    print(s)