def sgn(x):
    if x > 0 : return True
    else: return False



def solve():
    _  = int(input())
    data = [int(x) for x in input().split(" ")]
    s = 0
    i, n = 0, len(data)
    while(i < n):
        cur = data[i]
        j = i
        while(j < n and sgn(data[i]) == sgn(data[j])):
            cur = max(cur, data[j])
            j += 1
        s += cur
        i = j
    print(s)
    


nums = int(input())
for _ in range(1, nums + 1):
    solve()