def findsum(numberList):
    bigList = []
    sum = 0
    pos = 0
    neg = 0
    if numberList[0] > 0:
        pos = numberList[0]
    else:
        neg = numberList[0]

    for i in range(0,len(numberList)-1):
        if (pos < numberList[i+1] and numberList[i]*numberList[i+1] > 0 and numberList[i] > 0) or (numberList[i+1] > neg and numberList[i]*numberList[i+1] > 0 and numberList[i] < 0):
            if numberList[i] > 0:
                pos = numberList[i+1]
            else:
                neg = numberList[i+1]
        elif (numberList[i] < 0 and numberList[i+1] > 0) or (numberList[i] > 0 and numberList[i+1] < 0):
            if numberList[i] > 0:
                sum += pos
                bigList.append(pos)
                pos = 0
                neg = numberList[i+1]
            else:
                sum += neg
                bigList.append(neg)
                neg = 0
                pos = numberList[i+1]
    sum += pos
    sum += neg
    print(sum)

a = int(input())
for i in range(a):
    random = input()
    numbers = input().split()
    numbers = [int(i) for i in numbers]
    findsum(numbers)
