def solve():
    n = int(input())

    a = [int(i) for i in input().split()]

    sign = 0  # 1 - plus, 0- minus

    if a[0] > 0:
        sign = 1

    mx = a[0]
    sum = 0
    for i in a:
        if i > 0:
            if sign == 1:
                mx = max(mx, i)
            else:
                sum += mx
                mx = i
                sign = 1
        else:
            if sign == 1:
                sum += mx
                mx = i
                sign = 0
            else:
                mx = max(mx, i)
    sum += mx
    print(sum)


t = int(input())
for i in range(t):
    solve()