ans = []
for _ in range(int(input())):
    n = int(input())
    u = list(map(int, input().split()))
    k = u[0] // abs(u[0])
    mx = u[0]
    ansi = 0
    for i in range(1, n):
        if u[i] // abs(u[i]) == k:
            mx = max(mx, u[i])
        else:
            k = -k
            ansi += mx
            mx = u[i]
    ansi += mx
    ans.append(ansi)
print('\n'.join(map(str, ans)))
    
