def fun(n,l):
    prev=l[0]
    sum=prev
    flag=1
    for i in range(1,n):
        if prev>0 and l[i]<0:
            sum+=l[i]
            flag=0
            prev=l[i]
        elif prev<0 and l[i]>0:
            sum += l[i]
            flag = 0
            prev = l[i]
        elif prev<l[i]:
            prev=l[i]
            if flag==1:
                sum=prev
    print(sum)

for T in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    fun(n,l)