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