for i in range(int(input())):
    n=int(input())
    l=list(map(int,input().split()))
    a=[]
    for i in range(n):
        if i<n-1:
            if (l[i]*l[i+1])<0:
                a.append(l[i])
            else:
                if l[i]>l[i+1]:
                    (l[i],l[i+1])=(l[i+1],l[i])
        else:
            a.append(l[i])
                
            
    print(sum(a))