import pdb
queries = int(input())

for _ in range(queries):
    _ = input()
    array = [int(item) for item in input().split()]
    result = 0
    maxV = array[0]
    for item in range(1, len(array)):
        if (maxV > 0 and array[item] > 0 or maxV < 0 and array[item] < 0):
            if array[item] > maxV:
                maxV = array[item]
        else:
            result += maxV
            maxV = array[item]
    
    result += maxV
    print(result)
