from collections import defaultdict

def find_k(arr):
    z = local_max = arr[0]
    res = 0
    for x in arr[1:]:
        if z // abs(z) + x // abs(x) == 0:
            res += local_max
            z = local_max = x
        else:
            local_max = max(local_max, x)

    res += local_max
    return res


t = int(input())

for _ in range(t):
    n = int(input())

    a = list(map(int, input().split()))

    print(find_k(a))
