t=int(input())
i=0
while(i<t):
    n=int(input())
    array=list(map(int,input().split()))
    add=0
    diff=0
    maxi=0
    mini=99999999999999
    flag=2
    for i in array:
        if(i>0):
            maxi=max(maxi,i)
            if(flag==0):
                diff+=mini
                mini=99999999999999
                flag=1
        else:
            i=i*(-1)
            mini=min(mini,i)
            add+=maxi
            maxi=0
            flag=0
    if(mini==99999999999999):
       print(add+maxi-diff)
    else:
       print(add+maxi-mini-diff)
    i+=1