for q in range(int(input())):
    n=int(input())
    arr=list(map(int,input().split()))
    som=0
    maxm=arr[0]
    i,j=0,0
    while(i<n and j<n):
        if arr[i]>=0:
            maxm=-10**19
            while(j<n and arr[j]>=0):
                maxm=max(maxm,arr[j])
                j+=1
            som+=maxm
            i=j
        else:
            maxm=-10**19
            while(j<n and arr[j]<0):
                maxm=max(maxm,arr[j])
                j+=1
            som+=maxm
            i=j
    print(som)