t = int(input())

for i in range(t):
    n = int(input())
    arr = [int(j) for j in input().split(' ')]

    partitions = [[arr[0]]]
    index = 0

    for j in range(1, n):
        if arr[j] * arr[j - 1] > 0:
            partitions[index].append(arr[j])
        else:
            partitions.append([arr[j]])
            index += 1

    sum = 0
    for partition in partitions:
        sum += max(partition)

    print(sum)