t = int(input())
for i in range(t):
    n = int(input())
    ai = list(map(int,input().split()))
    
    num = ai[0]
    ans = 0
    for i in range(1,n):
        if (ai[i] > 0) == (ai[i-1] > 0):
            num = max(num,ai[i])
        else:
            ans += num
            num = ai[i]
    ans += num
    print(ans)
