for _ in range(int(input())):
    g = 0
    n = int(input())
    li=list(map(int,input().split()))
    fl=0
    ans=0
    if li[0]>0:
        fl=1
    else:
        fl=0
    maxi=li[0]
        
    for i in range(1,n):
        if (li[i]>0 and fl==0) or (li[i]<0 and fl==1):
            ans+=maxi
            fl=1-fl
            maxi=li[i]
            
        if li[i]>0 and fl==1:
            maxi=max(maxi,li[i])
        else:
            maxi=max(maxi,li[i])
        g+=1
    ans+=maxi
    print(ans+(g*0))