test = int(input())
for t in range(test):
    n = int(input())
    a = list(map(int, input().split()))
    
    last, res = a[0], 0
    for i in range(1, n):
        if (last >= 0 and a[i] >= 0) or (last <= 0 and a[i] <= 0):
            last = max(last, a[i])
        else:
            res += last
            last = a[i]
    
    res += last
    print(res)