for _ in range(int(input())):
    n = int(input())
    lst = list(map(int,input().split()))
    i = 0
    ans = 0
    while(i<n):
        if(lst[i]>0):
            j = i+1
            maxPos = lst[i]
            while(j<n and lst[j]>0):
                maxPos = max(maxPos,lst[j])
                j+=1
            ans+=maxPos
            i = j
        else:
            j =i+1
            maxNeg = lst[i]
            while(j<n and lst[j]<0):
                maxNeg = max(maxNeg,lst[j])
                j+=1
            ans+=maxNeg
            i = j
    print(ans)                        