t=int(input())
for i in range(t):
    n=int(input())
    a=[int(i) for i in input().split()]
    x=a[0]
    z=0
    j=0
    while(j<n):
        if a[j]*x<0:
            z=z+x
            x=a[j]
        else:
            x=max(x,a[j])
        j+=1
            
    print(z+x)
    