for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    summ=[l[0]]
    if l[0]>0:
        prev=1
    else:
        prev=0

    for i in l:
        if i>0 and prev==1:
            if i>summ[-1]:
                summ[-1]=i
        elif i<0 and prev==0:
            if i>summ[-1]:
                summ[-1]=i
        else:
            summ.append(i)
            prev= 0 if prev==1 else 1
    print(sum(summ))
