el = int(input())
for x in range(el):
    nums = int(input())
    ch = 0
    tempval = 0
    count = 0
    for y in input().split(' '):
        temp = int(y)
        if ch == -1:
            if temp > 0:
                ch = 1
                count = count + tempval
                tempval = temp
            else:
                if temp>tempval:
                    tempval = temp
        elif ch == 1:
            if temp < 0:
                ch = -1
                count = count + tempval
                tempval = temp
            else:
                if temp>tempval:
                    tempval = temp
        else:
            tempval = temp
            if temp>0:
                ch = 1
            else:
                ch = -1
    print(count + tempval)
