T = int(input())
for x in range(T):
    N = int(input())
    A = list(map(int, input().split()))
    maxSum = 0
    lastNo = A[0]
    for a in A:
        if(lastNo < 0 and a>0):
            maxSum+=lastNo
            lastNo = a
        elif(lastNo > 0 and a < 0):
            maxSum+=lastNo
            lastNo = a
        elif(a > lastNo):
            lastNo = a
    maxSum+=lastNo
    print(maxSum)