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