t=int(input())
while(t>0):
    n=int(input())
    d={}
    a = list(map(int,input().split()))
    length=1
    s=int(a[0])
    d[1]=[int(s)]
    for j in range (1,len(a)):
        d[1].append(int(a[j]))
        if (int(a[j])*int(a[j-1])<0):
            length+=1
            s+=int(a[j])
        else:
            if length in d:
                d[length].append(s)
            else:
                d[length]=[s]
                s=int(a[j])
                length=1
    print (max(d[max(d.keys())]))
    t-=1

        