te = int(input())
while te:
    n = int(input())
    l = list(map(int,input().split()))
    t = []
    start,end=0,0
    while end < n:
        if l[start]*l[end] > 0:
            end+=1
        else:
            t.append(max(l[start:end]))
            start=end
    t.append(max(l[start:end]))
    print(sum(t))
    te-=1

