def get_sign(v):
    return 1 if v > 0 else -1

def solve(arr):
    compressed = []
    smallest = min(arr)
    cur = smallest

    for i in range(0, len(arr)):
        if i != 0 and cur * arr[i] < 0:
            compressed.append(cur)
            cur = smallest
        cur = max(cur, arr[i])
    compressed.append(cur)
    return sum(compressed)


for _ in range(int(input())):
    n = int(input())
    *arr, = map(int, input().split())
    print(solve(arr))
