p=int(input())
for z in range(p):
    n=int(input())
    s=[]
    a=0
    b=0
    more=False
    less=False
    f=input().split()
    for i in range(n):
        s.append(int(f[i]))
        if (int(f[i]))>0 and more==False:
            more=True
            a=i
        if (int(f[i]))<0 and less==False:
            less=True
            b=i
    more,less=a,b
    prev=True
    mc=[]
    mg=[]
    slic=[]
    for i in range(more,n):
        a=s[i]
        if (a>0 and not prev) or (a<0 and prev):
            mc.append(slic)
            slic=[a]
            if not prev:
                prev=True
            else:
                prev=False
        else:
            slic.append(a)
    if slic!=[]:
        mc.append(slic)
        slic=[]


    prev=False
    for i in range(less,n):
        a=s[i]
        if (a>0 and not prev) or (a<0 and prev):
            mg.append(slic)
            slic=[a]
            if not prev:
                prev=True
            else:
                prev=False
        else:
            slic.append(a)
    if slic!=[]:
        mg.append(slic)
    s=[]
    if len(mc)>len(mg):
        s.append(mc)
    elif len(mg)>len(mc):
        s.append(mg)
    else:
        s.append(mc)
        s.append(mg)
    summ=[]
    for i in s:
        x=0
        for j in i:
            if j!=[]:
                x+=max(j)
        summ.append(x)
    print(max(summ))






    









                
