t=int(input())
for _ in range(t):
    n=int(input())
    l=list(map(int,input().strip().split()))
    sum=0
    a=[]
    for i in range(n):
        if i==0:
            a.append(l[i])
        else:
            if a[-1]<0 and l[i]<0:
                a.append(l[i])
            elif a[-1]>0 and l[i]>0:
                a.append(l[i])
            else:
                b=max(a)
                sum=sum+b
                a.clear()
                a.append(l[i])
    print(sum +max(a))