t = int(input())

ans = []
for i in range(t):
    n = int(input())
    seq = [int(num) for num in input().split()]
    res = 0
    buff = seq[0]
    for j in range(1, n):
        if (buff < 0 and seq[j] < 0) or (buff > 0 and seq[j] > 0):
            buff = max(buff, seq[j])
        else:
            res += buff
            buff = seq[j]
    res += buff
    ans.append(res)

print(*ans, sep='\n')
