for _ in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    i=0
    s=0
    m=-9999999999
    while i<n:
        if i<n and l[i]>0 :
            while i<n and l[i]>0 :
                m=max(m,l[i])
                i+=1
            s+=m
            m=-9999999999
        elif i<n and l[i]<0:
            while i<n and l[i]<0:
                m=max(m,l[i])
                i+=1
            s+=m
            m=-9999999999
        else:
            i+=1
    print(s)
             