for a0 in range(int(input())):
    n=int(input())
    l=[int(x) for x in input().split()]
    z=[]
    z.append([l[0]])
    current = l[0]>0
    for i in range(1,n):
        if l[i]>0 and current:
            z[-1].append(l[i])
        elif l[i]<0 and not current:
            z[-1].append(l[i])
        else:
            z.append([l[i]])
            if current==True:
                current=False
            else:
                current=True
    sum=0
    for i in z:
        sum+=max(i)
    print(sum)
