t = int(input())
while(t>0):
    t-=1
    n = int(input())
    arr = list(map(int,input().split()))
    ans = 0
    mini  = -10000000000
    maxu = 0
    tougle = 0
    for i in range(n):
        #print(arr[i],maxu,mini,ans)
        if(i==0):
            if(arr[i]>0):
                maxu = arr[i]
                tougle = 1
            else:
                mini = arr[i]
                tougle = -1
        else:
            if(tougle==1 and arr[i]<0):
                tougle = -1
                ans+=maxu
                maxu = 0
            elif(tougle==-1 and arr[i]>0):
                tougle = 1
                ans+=mini
                mini =  -10000000000

            if(tougle==1):
                if(arr[i]>maxu):
                    maxu = arr[i]
            else:
                if(arr[i]>mini):
                    mini = arr[i]
    
    #print(ans,tougle,mini,maxu)
    if(tougle==1):
        ans+=maxu
    else:
        ans+=mini
    print(ans)
                