#python 3.6.9

for w in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    c,i,s=0,0,0
    l2=[]
    while c!=n:
        l1=[]
        if l[i]>0:
            for j in range(i,n):
                if l[j]>0:
                    l1.append(l[j])
                    c+=1
                else:
                    i=j
                    break
        else:
            for j in range(i,n):
                if l[j]<0:
                    l1.append(l[j])
                    c+=1
                else:
                    i=j
                    break
        l2.append(l1)
    for i in l2:
        s=s+max(i)
    print(s)