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

for T in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    if n>1:
        fun(n,l)
    else:
        print(l[0])