for _ in range(int(input())):
    n=int(input())
    a=[int(i) for i in input().split()]
    a.append(0)
    b=[]
    c=[]
    for i in range(n):
        c.append(a[i])
        if (a[i+1]>0 and a[i]>0) or (a[i+1]<0 and a[i]<0):
            c.append(a[i+1])
        else:
            b.append(max(c))
            c=[]
    print(sum(b))
    
