t = int(input())
for _ in range(t):
    a = int(input())
    b = list(map(int, input().split(' ')))
    maxm = b[0]
    ans = 0
    for i in range(1, a):
        if (b[i]*b[i-1]) < 0:
            ans += maxm
            maxm = float('-inf')
        maxm = max(maxm, b[i])
    ans += maxm
    print (ans)
