test_cases= int(input())
data = []
while test_cases > 0:
    length = input()
    data.append(list(map(int,input().split())))
    test_cases -= 1

for i in range(0,len(data)):
    data[i].append(0)
    maxLength = 1
    for j in range(0,len(data[i])-1):
        if (data[i][j] < 0 and data[i][j+1] > 0) or (data[i][j] > 0 and data[i][j+1] < 0):
            maxLength += 1
    travel = 0
    maxAdd = data[i][0]
    maxSum = 0
    while maxLength > 0:
        if (data[i][travel] > 0 and data[i][travel+1] > 0) or (data[i][travel] < 0 and data[i][travel+1] < 0):
            maxAdd = max(maxAdd,data[i][travel+1])
            travel += 1
        else:
            maxSum += maxAdd
            maxLength -= 1
            travel += 1
            maxAdd = data[i][travel]
    print(maxSum)