for j in[*open(0)][2::2]:
    l=[*map(int,j.split())]
    q,w,r=l[0],[],[]
    for i in l:
        if q*i>0:r+=[i]
        else:
            q*=-1
            w+=[max(r)]
            r=[i]
    print(sum(w)+max(r))